public MainPage() { this.InitializeComponent(); ink.InkPresenter.InputDeviceTypes = Windows.UI.Core.CoreInputDeviceTypes.Touch | Windows.UI.Core.CoreInputDeviceTypes.Pen | Windows.UI.Core.CoreInputDeviceTypes.Mouse; ink.InkPresenter.StrokeInput.StrokeContinued += StrokeInput_StrokeContinued; ink.InkPresenter.StrokesCollected += InkPresenter_StrokesCollected; var vec1 = new Vector() { Start = new Point() { X = 0, Y = 0 }, End = new Point { X = 1, Y = 1 } }; var vec2 = new Vector() { Start = new Point() { X = 0, Y = 0 }, End = new Point { X = 1, Y = 0 } }; System.Diagnostics.Debug.WriteLine("Ängle =" + vec2.Angle(vec1)); inkRecognizerContainer = new InkRecognizerContainer(); recoView = inkRecognizerContainer.GetRecognizers(); // Set the text services so we can query when language changes textServiceManager = CoreTextServicesManager.GetForCurrentView(); textServiceManager.InputLanguageChanged += TextServiceManager_InputLanguageChanged; SetDefaultRecognizerByCurrentInputMethodLanguageTag(); }
public double Angle(Vector other) { return (Math.Atan2(other.Y, other.X) - Math.Atan2(this.Y, this.X)) * 180 / Math.PI; }
public double Distance(Vector other) { return Math.Sqrt(Math.Pow(this.Start.X - other.End.X, 2) + Math.Pow(this.Start.Y - other.End.Y, 2)); }
private async void Detect(List<Point> points) { var vectors = new List<Vector>(); vectors.Add(new Vector() { Start = points[0], End = points[1] }); var added = 0; var skiped = 0; for (int i = 2; i < points.Count; i++) { var vector1 = vectors[vectors.Count - 1]; var vector2 = new Vector() { Start = points[i - 1], End = points[i] }; if (Math.Abs(vector1.Angle(vector2)) > 25) { System.Diagnostics.Debug.WriteLine("angle " + Math.Abs(vector1.Angle(vector2))); vectors.Add(vector2); added++; } else { vectors[vectors.Count - 1] = new Vector() { Start = vector1.Start, End = vector2.End }; skiped++; } } vectors = vectors.Where(v => v.Long > 50).ToList(); System.Diagnostics.Debug.WriteLine("added {0} - skiped {1}", added, skiped); System.Diagnostics.Debug.WriteLine("Cantidad de vectores detectados: {0}", vectors.Count); if (vectors.Count == 0) return; var shape = new Shape(vectors); System.Diagnostics.Debug.WriteLine("the shape is {0}", shape.IsClosed ? "closed" : "open", 1); var dp = shape.DrawPoints; dp.Add(dp.First()); var vecs = dp.Zip(dp.Skip(1), (a, b) => new Vector() { Start = a, End = b }).ToList(); // if (shape.IsClosed || shape.Vectors.Count < 2) vectors.ForEach(v => { var line = new Line(); line.StrokeThickness = 4; line.X1 = v.Start.X; line.X2 = v.End.X; line.Y1 = v.Start.Y; line.Y2 = v.End.Y; line.Stroke = new SolidColorBrush(Color.FromArgb(255, 255, 100, 0)); canvas.Children.Add(line); }); vectors.ForEach(vector => System.Diagnostics.Debug.WriteLine("Vector: {0} a {1} => {2} Long => {3}", vector.Start, vector.End, vector.ToZero, vector.Long) ); var rec = shape.DetectShape(); if (rec == "Nothing") OnRecognizeAsync(null, null); else shapeText.Text = rec; }