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; }
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 }); }
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); } }
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; }