本文整理汇总了C#中System.Drawing.PointF.DistanceTo方法的典型用法代码示例。如果您正苦于以下问题:C# PointF.DistanceTo方法的具体用法?C# PointF.DistanceTo怎么用?C# PointF.DistanceTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.PointF
的用法示例。
在下文中一共展示了PointF.DistanceTo方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ApplyPoint
public void ApplyPoint(PointF point)
{
var offset = point.Subtract(_startPoint);
if (points.Count == 0)
{
points.Add(new GesturePoint { X = offset.X, Y = offset.Y, threshold = 10 });
}
else
{
var last = points.Last();
var lastPoint = new PointF(last.X, last.Y);
// first check distance from last point
if (lastPoint.DistanceTo(offset) > 10)
{
var currentAngle = _previousOffset.AngleTo(offset);
var previousAngle = lastPoint.AngleTo(_previousOffset);
var da = currentAngle - previousAngle;
if (da < -Math.PI) da += 2 * Math.PI;
if (da > Math.PI) da -= 2 * Math.PI;
if (da > 0.1)
{
AddPoint(_previousOffset);
}
}
}
_previousOffset = offset;
}
示例2: AddPoint
private void AddPoint(PointF p)
{
var last = points.Last();
var lastPoint = new PointF(last.X, last.Y);
var dist = p.DistanceTo(lastPoint);
float thresh = (float)dist / 2;
thresh = Math.Max(thresh, 30);
points.Add(new GesturePoint { X = p.X, Y = p.Y, threshold = thresh });
}
示例3: GetHandWidthBetween
private float GetHandWidthBetween(PointF p1, PointF p2)
{
float slope = Math.Abs(p2.X - p1.X) / p2.DistanceTo(p1);
PointF p3 = new PointF();
PointF p4 = new PointF();
if (slope < 0.707)//vert
{
for (int Y = 0; Y < Math.Abs(p2.Y - p1.Y); Y++)
{
p3 = InterPolateP(p1, p2, Y / (p2.Y - p1.Y));
if (IsHand(p3)) break;
}
for (int Y = 0; Y < Math.Abs(p2.Y - p1.Y); Y++)
{
p4 = InterPolateP(p2, p1, Y / (p2.Y - p1.Y));
if (IsHand(p4)) break;
}
return p3.DistanceTo(p4);
}
else//hori
{
for (int x = 0; x < Math.Abs(p2.X - p1.X); x++)
{
p3 = InterPolateP(p1, p2, x / (p2.X - p1.X));
if (IsHand(p3)) break;
}
for (int x = 0; x < Math.Abs(p2.X - p1.X); x++)
{
p4 = InterPolateP(p2, p1, x / (p2.X - p1.X));
if (IsHand(p4)) break;
}
return p3.DistanceTo(p4);
}
}
示例4: ProcessNext
public State ProcessNext(PointF next)
{
var currentDateTime = _currentTime();
if (StartTime == default(DateTime))
StartTime = currentDateTime;
EndTime = currentDateTime;
AvgCenter = new PointF(
AvgCenter.X * Count / (Count + 1) + next.X / (Count + 1),
AvgCenter.Y * Count / (Count + 1) + next.Y / (Count + 1)
);
MaxCenter = new PointF(Math.Max(MaxCenter.X, next.X), Math.Max(MaxCenter.Y, next.Y));
MinCenter = new PointF(Math.Min(MaxCenter.X, next.X), Math.Min(MaxCenter.Y, next.Y));
if (LastCenter.HasValue)
{
if (LastCenter.Value.X < AvgCenter.X && AvgCenter.X <= next.X)
{
XAmplitudes.Add(Math.Abs(MinCenter.X - -AvgCenter.X)* 2);
MinCenter = new PointF(AvgCenter.X, MinCenter.Y);
}
if (LastCenter.Value.X > AvgCenter.X && AvgCenter.X >= next.X)
{
XAmplitudes.Add(Math.Abs(MaxCenter.X - AvgCenter.X) *2);
MaxCenter = new PointF(AvgCenter.X, MaxCenter.Y);
}
if (LastCenter.Value.Y < AvgCenter.Y && AvgCenter.Y <= next.Y)
{
YAmplitudes.Add(Math.Abs(MinCenter.Y - AvgCenter.Y)*2);
MinCenter = new PointF(MinCenter.X, AvgCenter.Y);
}
if (LastCenter.Value.Y > AvgCenter.Y && AvgCenter.Y >= next.Y)
{
YAmplitudes.Add(Math.Abs(MaxCenter.Y - AvgCenter.Y)*2);
MaxCenter = new PointF(MaxCenter.X, AvgCenter.Y);
}
}
var length = LastCenter.HasValue ? Indicators.Length + next.DistanceTo(LastCenter.Value) : Indicators.Length;
var frequencyX = XAmplitudes.Count / (EndTime - StartTime).TotalSeconds;
var frequencyY = YAmplitudes.Count / (EndTime - StartTime).TotalSeconds;
var periodX = XAmplitudes.Count == 0 ? 0 : 1 / frequencyX;
var periodY = YAmplitudes.Count == 0 ? 0 : 1 / frequencyY;
Indicators = new Indicators
{
Length = length,
Frequency = new PointF((float)frequencyX, (float)frequencyY),
Period = new PointF((float)periodX, (float)periodY),
AvgAmplitude = new PointF(
XAmplitudes.Count == 0 ? 0f : (float)XAmplitudes.Average(),
YAmplitudes.Count == 0 ? 0f : (float)YAmplitudes.Average()),
MaxAmplitude = new PointF(
XAmplitudes.Count == 0 ? 0f : (float)XAmplitudes.Max(),
YAmplitudes.Count == 0 ? 0f : (float)YAmplitudes.Max())
};
Count = Count + 1;
LastCenter = next;
return this;
}