private Intersection linesIntersect(LineSegment a, LineSegment b)
Intersection linesIntersect(LineSegment a, LineSegment b)
  private Intersection linesIntersect(LineSegment a, LineSegment b)  {    Point2D P1 = a.P1;    Point2D P2 = a.P2;    Point2D P3 = b.P1;    Point2D P4 = b.P2;    if (! Line2D.linesIntersect(P1.getX(), P1.getY(), P2.getX(), P2.getY(),                                P3.getX(), P3.getY(), P4.getX(), P4.getY()))      return null;    double x1 = P1.getX();    double y1 = P1.getY();    double rx = P2.getX() - x1;    double ry = P2.getY() - y1;    double x2 = P3.getX();    double y2 = P3.getY();    double sx = P4.getX() - x2;    double sy = P4.getY() - y2;    double determinant = sx * ry - sy * rx;    double nom = (sx * (y2 - y1) + sy * (x1 - x2));    // Parallel lines don't intersect. At least we pretend they don't.    if (Math.abs(determinant) < EPSILON)      return null;    nom = nom / determinant;    if (nom == 0.0)      return null;    if (nom == 1.0)      return null;    Point2D p = new Point2D.Double(x1 + nom * rx, y1 + nom * ry);    return new Intersection(p, p.distance(P1) / P1.distance(P2),                            p.distance(P3) / P3.distance(P4));  }