public static Coordinate intersection(Coordinate p1,Coordinate p2,Coordinate q1,Coordinate q2) throws NotRepresentableException {
  double px=p1.y - p2.y;
  double py=p2.x - p1.x;
  double pw=p1.x * p2.y - p2.x * p1.y;
  double qx=q1.y - q2.y;
  double qy=q2.x - q1.x;
  double qw=q1.x * q2.y - q2.x * q1.y;
  double x=py * qw - qy * pw;
  double y=qx * pw - px * qw;
  double w=px * qy - qx * py;
  double xInt=x / w;
  double yInt=y / w;
  if ((Double.isNaN(xInt)) || (Double.isInfinite(xInt) || Double.isNaN(yInt)) || (Double.isInfinite(yInt))) {
    throw new NotRepresentableException();
  }
  return new Coordinate(xInt,yInt);
}

public static Coordinate intersection ( Coordinate p1 , Coordinate p2 , Coordinate q1 , Coordinate q2 ) throws NotRepresentableException { double px = p1 . y - p2 . y ; double py = p2 . x - p1 . x ; double pw = p1 . x * p2 . y - p2 . x * p1 . y ; double qx = q1 . y - q2 . y ; double qy = q2 . x - q1 . x ; double qw = q1 . x * q2 . y - q2 . x * q1 . y ; double x = py * qw - qy * pw ; double y = qx * pw - px * qw ; double w = px * qy - qx * py ; double xInt = x / w ; double yInt = y / w ; if ( ( Double . isNaN ( xInt ) ) || ( Double . isInfinite ( xInt ) || Double . isNaN ( yInt ) ) || ( Double . isInfinite ( yInt ) ) ) { throw new NotRepresentableException ( ) ; } return new Coordinate ( xInt , yInt ) ; }
computes the ( approximate ) intersection point between two line segments using homogeneous coordinates . < p > note that this algorithm is not numerically stable ; i . e . it can produce intersection points which lie outside the envelope of the line segments themselves . in order to increase the precision of the calculation input points should be normalized before passing them to this routine .
