public static final Point2DArray intersectLineArcTo ( final Point2D a0 , final Point2D a1 , final Point2D p0 , final Point2D p1 , final Point2D p2 , final double r ) { final Point2DArray arcPoints = getCanvasArcToPoints ( p0 , p1 , p2 , r ) ; final Point2DArray circleIntersectPoints = intersectLineCircle ( a0 , a1 , arcPoints . get ( 1 ) , r ) ; final Point2DArray arcIntersectPoints = new Point2DArray ( ) ; Point2D ps = arcPoints . get ( 0 ) ; final Point2D pc = arcPoints . get ( 1 ) ; Point2D pe = arcPoints . get ( 2 ) ; if ( ! ps . equals ( p0 ) ) { // canvas draws a line form p0 to p1, this is a new potential intersection point final Point2D t = intersectLineLine ( p0 , ps , a0 , a1 ) ; if ( t != null ) { arcIntersectPoints . push ( t ) ; } } if ( ( pe . sub ( pc ) ) . crossScalar ( ( ps . sub ( pc ) ) ) < 0 ) { // reverse to make counterclockwise final Point2D t = pe ; pe = ps ; ps = t ; } // As the intersect is on the circle, rather than the arc, it can return back two points. // However we know only one of those points is both on the arc and on the line. // This means a simple bounding box check on the intersect points and the line can be used. if ( circleIntersectPoints . size ( ) > 0 ) { final Point2D t = circleIntersectPoints . get ( 0 ) ; final boolean within = intersectPointWithinBounding ( t , a0 , a1 ) ; // check which points are on the arc. page 4 http://www.geometrictools.com/Documentation/IntersectionLine2Circle2.pdf if ( within && ( t . sub ( ps ) . dot ( pe . sub ( ps ) . perpendicular ( ) ) >= 0 ) ) { arcIntersectPoints . push ( t ) ; } } if ( circleIntersectPoints . size ( ) == 2 ) { final Point2D t = circleIntersectPoints . get ( 1 ) ; final boolean within = intersectPointWithinBounding ( t , a0 , a1 ) ; // check which points are on the arc. page 4 http://www.geometrictools.com/Documentation/IntersectionLine2Circle2.pdf if ( within && ( t . sub ( ps ) . dot ( pe . sub ( ps ) . perpendicular ( ) ) >= 0 ) ) { arcIntersectPoints . push ( t ) ; } } return arcIntersectPoints ; }
Returns the points the line intersects the arcTo path . Note that as arcTo s points are actually two lines form p1 at a tangent to the arc s circle it can draw a line from p0 to the start of the arc which forms another potential intersect point .