private static Point getLinesIntersection ( Line2D a , Line2D b ) { double d = ( a . getX1 ( ) - a . getX2 ( ) ) * ( b . getY2 ( ) - b . getY1 ( ) ) - ( a . getY1 ( ) - a . getY2 ( ) ) * ( b . getX2 ( ) - b . getX1 ( ) ) ; double da = ( a . getX1 ( ) - b . getX1 ( ) ) * ( b . getY2 ( ) - b . getY1 ( ) ) - ( a . getY1 ( ) - b . getY1 ( ) ) * ( b . getX2 ( ) - b . getX1 ( ) ) ; double ta = da / d ; Point p = new Point ( ) ; p . setLocation ( a . getX1 ( ) + ta * ( a . getX2 ( ) - a . getX1 ( ) ) , a . getY1 ( ) + ta * ( a . getY2 ( ) - a . getY1 ( ) ) ) ; return p ; }
This method calculates intersections of two lines .