/** * Check to see if stroke is a standard arrow * * @return true if test passes; else false */ protected bool checkStandardArrow() { bool passed = true; StylusPointCollection last = m_subStrokes[m_subStrokes.Count - 1]; StylusPointCollection secondLast = m_subStrokes[m_subStrokes.Count - 2]; StylusPointCollection thirdLast = m_subStrokes[m_subStrokes.Count - 3]; StylusPointCollection fourthLast = m_subStrokes[m_subStrokes.Count - 4]; double lastLength = Recognizer.getStrokeLength(last); double secondLastLength = Recognizer.getStrokeLength(secondLast); double thirdLastLength = Recognizer.getStrokeLength(thirdLast); // test 1: last two sub-strokes must be close in size m_lastTwoDiff = Math.Abs(lastLength - secondLastLength) / (lastLength + secondLastLength); if (m_lastTwoDiff > 0.5) { passed = false; } // test 2: two points at the "head" of the arrow should be close m_headDistance = distance(last[0], thirdLast[0]) / recognizer.getStrokeLength(); if (m_headDistance > 0.11) { passed = false; } m_standardSum = m_headDistance; // test 3: line connecting tips of arrow head should intersect shaft of // arrow Line2D.Double line1 = new Line2D.Double( thirdLast[thirdLast.Count - 1].X, thirdLast[thirdLast.Count - 1].Y, last[last.Count - 1].X, last[last.Count - 1].Y); List <Point2D> intersect = Recognizer.getIntersection( fourthLast, line1); m_numIntersect = intersect.Count; if (m_numIntersect <= 0) { passed = false; } // Line2D.Double line2 = new Line2D.Double(fourthLast.getPoints().get( // fourthLast.getNumPoints() / 2).getX(), fourthLast.getPoints() // .get(fourthLast.getNumPoints() / 2).getY(), fourthLast // .getLastPoint().getX(), fourthLast.getLastPoint().getY()); // double perpDiff = Math.abs(getSlope(line1) - (1.0 / // getSlope(line2))); // if (perpDiff > 5) // passed = false; return(passed); }
/** * Estimate the minor axis of the ellipse (perpendicular bisector of the * major axis; clipped where it intersects the stroke) */ protected void calcMinorAxis() { PerpendicularBisector bisect = new PerpendicularBisector( m_majorAxis.GetP1(), m_majorAxis.GetP2(), recognizer.getBounds()); List <Point2D> intersectPts = recognizer.getIntersection(bisect .getBisector()); if (intersectPts.Count < 2) { m_minorAxis = null; m_minorAxisLength = 0.0; } else { double d1, d2; d1 = m_center.Distance(intersectPts[0]); d2 = m_center.Distance(intersectPts[1]); m_minorAxis = new Line2D.Double(intersectPts[0].X, intersectPts[0].Y, intersectPts[1].X, intersectPts[1].Y); m_minorAxisLength = d1 + d2; } }
public PerpendicularBisector(Point2D p1, Point2D p2, BoundingBox bounds) { this.point2D1 = p1; this.point2D2 = p2; this.boundingBox = bounds; double xMid = ((p2.X - p1.X) / 2) + p1.X; double yMid = ((p2.Y - p1.Y) / 2) + p1.Y; midPoint = new Point2D(xMid, yMid); if ((p2.Y - p1.Y) == 0) { // line is horizontal, slope 0 // perpendicular bisector is slope infinity bisectorSlope = double.NaN; } else if ((p2.X - p1.X) == 0) { // line is vertical, slope infinity // perpendicular bisector is slope 0 bisectorSlope = 0; } else { bisectorSlope = -1 * (p2.X - p1.X) / (p2.Y - p1.Y); } double x1, y1, x2, y2; if (double.IsNaN(bisectorSlope)) { // vertical bisectorYIntercept = double.NaN; y1 = bounds.getMinY(); y2 = bounds.getMaxY(); x1 = midPoint.X; x2 = midPoint.X; } else if (bisectorSlope == 0) { // horizontal bisectorYIntercept = midPoint.Y; y1 = midPoint.Y; y2 = midPoint.Y; x1 = bounds.getMinX(); x2 = bounds.getMaxX(); } else { // solve for y intercept // y = mx + b double y = midPoint.Y; double x = midPoint.X; double m = bisectorSlope; double b = y - (m * x); bisectorYIntercept = b; x1 = bounds.getMinX(); x2 = bounds.getMaxX(); if (double.IsNaN(m)) { y1 = bounds.getMinY(); y2 = bounds.getMaxY(); } else { y1 = m * x1 + b; y2 = m * x2 + b; } } bisector = new Line2D.Double(x1, y1, x2, y2); }