protected virtual void Setup() { var resampled = PointsHelpers.Resample(OriginalPoints, PointsHelpers.NumPoints); var radians = PointsHelpers.IndicativeAngle(resampled); var rotated = PointsHelpers.RotateBy(resampled, -radians); var scaled = PointsHelpers.ScaleTo(rotated, PointsHelpers.SquareSize); Points = PointsHelpers.TranslateTo(scaled, PointsHelpers.Origin); Vector = PointsHelpers.Vectorize(Points); // for Protractor }
protected override void Setup() { var resampled = PointsHelpers.Resample(OriginalPoints, PointsHelpers.NumPoints); var radians = PointsHelpers.IndicativeAngle(resampled); var rotated = PointsHelpers.RotateBy(resampled, -radians); var scaled = PointsHelpers.ScaleDimTo(rotated, PointsHelpers.SquareSize, PointsHelpers.OneDThreshold); if (UseBoundedRotationInvariance) { scaled = PointsHelpers.RotateBy(scaled, -radians); } this.StartUnitVector = PointsHelpers.CalcStartUnitVector(scaled, PointsHelpers.StartAngleIndex); this.Vector = PointsHelpers.Vectorize2(scaled, UseBoundedRotationInvariance); }
public Result Recognize(List <Point> points, bool useProtractor = true) { if (points.Count < 4) { return(Result.TooFewPoints()); } Rectangle rect = PointsHelpers.BoundingBox(points); points = PointsHelpers.Resample(points, PointsHelpers.NumPoints); var radians = PointsHelpers.IndicativeAngle(points); points = PointsHelpers.RotateBy(points, -radians); points = PointsHelpers.ScaleTo(points, PointsHelpers.SquareSize); points = PointsHelpers.TranslateTo(points, PointsHelpers.Origin); var vector = PointsHelpers.Vectorize(points); // for Protractor var b = Double.PositiveInfinity; var u = -1; for (var i = 0; i < this.Unistrokes.Count; i++) // for each unistroke { double d; if (useProtractor) // for Protractor { d = PointsHelpers.OptimalCosineDistance(this.Unistrokes[i].Vector, vector); } else // Golden Section Search (original $1) { d = PointsHelpers.DistanceAtBestAngle(points, this.Unistrokes[i], -PointsHelpers.AngleRange, +PointsHelpers.AngleRange, PointsHelpers.AnglePrecision); } if (d < b) { b = d; // best (least) distance u = i; // unistroke } } return((u == -1) ? new Result("No match.", 0.0, 0, Rectangle.Empty) : new Result(Unistrokes[u].Name, useProtractor ? 1.0 / b : 1.0 - b / PointsHelpers.HalfDiagonal, radians, rect)); }