public static int intersectLineLine(double a1x,double a1y,double a2x,double a2y,double b1x,double b1y,double b2x,double b2y,Point2D intersect){
  double ua_t=(b2x - b1x) * (a1y - b1y) - (b2y - b1y) * (a1x - b1x);
  double ub_t=(a2x - a1x) * (a1y - b1y) - (a2y - a1y) * (a1x - b1x);
  double u_b=(b2y - b1y) * (a2x - a1x) - (b2x - b1x) * (a2y - a1y);
  if (u_b != 0) {
    double ua=ua_t / u_b;
    double ub=ub_t / u_b;
    if (0 <= ua && ua <= 1 && 0 <= ub && ub <= 1) {
      intersect.setLocation(a1x + ua * (a2x - a1x),a1y + ua * (a2y - a1y));
      return 1;
    }
 else {
      return NO_INTERSECTION;
    }
  }
 else {
    return (ua_t == 0 || ub_t == 0 ? COINCIDENT : PARALLEL);
  }
}

public static int intersectLineLine ( double a1x , double a1y , double a2x , double a2y , double b1x , double b1y , double b2x , double b2y , Point2D intersect ) { double ua_t = ( b2x - b1x ) * ( a1y - b1y ) - ( b2y - b1y ) * ( a1x - b1x ) ; double ub_t = ( a2x - a1x ) * ( a1y - b1y ) - ( a2y - a1y ) * ( a1x - b1x ) ; double u_b = ( b2y - b1y ) * ( a2x - a1x ) - ( b2x - b1x ) * ( a2y - a1y ) ; if ( u_b != 0 ) { double ua = ua_t / u_b ; double ub = ub_t / u_b ; if ( 0 <= ua && ua <= 1 && 0 <= ub && ub <= 1 ) { intersect . setLocation ( a1x + ua * ( a2x - a1x ) , a1y + ua * ( a2y - a1y ) ) ; return 1 ; } else { return NO_INTERSECTION ; } } else { return ( ua_t == 0 || ub_t == 0 ? COINCIDENT : PARALLEL ) ; } }
compute the intersection of two line segments .
