public static Point2D intersection(final Line2D l1,final Line2D l2){
  Point2D p0=l1.getP1();
  Point2D d0=new Point2D.Double(l1.getX2() - p0.getX(),l1.getY2() - p0.getY());
  Point2D p1=l2.getP1();
  Point2D d1=new Point2D.Double(l2.getX2() - p1.getX(),l2.getY2() - p1.getY());
  Point2D e=new Point2D.Double(p1.getX() - p0.getX(),p1.getY() - p0.getY());
  double kross=d0.getX() * d1.getY() - d0.getY() * d1.getX();
  double sqrKross=kross * kross;
  double sqrLen0=d0.distanceSq(0.0,0.0);
  double sqrLen1=d1.distanceSq(0.0,0.0);
  if (sqrKross > EPSILON_SQ * sqrLen0 * sqrLen1) {
    double s=(e.getX() * d1.getY() - e.getY() * d1.getX()) / kross;
    if (s < 0d || s > 1d) {
      return null;
    }
    double t=(e.getX() * d0.getY() - e.getY() * d0.getX()) / kross;
    if (t < 0d || t > 1d) {
      return null;
    }
    return new Point2D.Double(p0.getX() + s * d0.getX(),p0.getY() + s * d0.getY());
  }
  return null;
}

public static Point2D intersection ( final Line2D l1 , final Line2D l2 ) { Point2D p0 = l1 . getP1 ( ) ; Point2D d0 = new Point2D . Double ( l1 . getX2 ( ) - p0 . getX ( ) , l1 . getY2 ( ) - p0 . getY ( ) ) ; Point2D p1 = l2 . getP1 ( ) ; Point2D d1 = new Point2D . Double ( l2 . getX2 ( ) - p1 . getX ( ) , l2 . getY2 ( ) - p1 . getY ( ) ) ; Point2D e = new Point2D . Double ( p1 . getX ( ) - p0 . getX ( ) , p1 . getY ( ) - p0 . getY ( ) ) ; double kross = d0 . getX ( ) * d1 . getY ( ) - d0 . getY ( ) * d1 . getX ( ) ; double sqrKross = kross * kross ; double sqrLen0 = d0 . distanceSq ( 0.0 , 0.0 ) ; double sqrLen1 = d1 . distanceSq ( 0.0 , 0.0 ) ; if ( sqrKross > EPSILON_SQ * sqrLen0 * sqrLen1 ) { double s = ( e . getX ( ) * d1 . getY ( ) - e . getY ( ) * d1 . getX ( ) ) / kross ; if ( s < 0d || s > 1d ) { return null ; } double t = ( e . getX ( ) * d0 . getY ( ) - e . getY ( ) * d0 . getX ( ) ) / kross ; if ( t < 0d || t > 1d ) { return null ; } return new Point2D . Double ( p0 . getX ( ) + s * d0 . getX ( ) , p0 . getY ( ) + s * d0 . getY ( ) ) ; } return null ; }
returns the intersection point of two lines .
