public boolean intersects ( LineSegment lineSegment ) { double x1 = this . x1 ( ) ; double y1 = this . y1 ( ) ; double x2 = this . x2 ( ) ; double y2 = this . y2 ( ) ; double x3 = lineSegment . x1 ( ) ; double y3 = lineSegment . y1 ( ) ; double x4 = lineSegment . x2 ( ) ; double y4 = lineSegment . y2 ( ) ; double denom = ( y4 - y3 ) * ( x2 - x1 ) - ( x4 - x3 ) * ( y2 - y1 ) ; if ( denom == 0 ) { return false ; } double u1 = ( ( x4 - x3 ) * ( y1 - y3 ) - ( y4 - y3 ) * ( x1 - x3 ) ) / denom ; double u2 = ( ( x2 - x1 ) * ( y1 - y3 ) - ( y2 - y1 ) * ( x1 - x3 ) ) / denom ; return ( u1 > 0 && u1 < 1 && u2 > 0 && u2 < 1 ) ; }
Does this linesegment intersect with another or not?