public Point pointOfIntersection(Line l) {
        // Four points of two line and point of intersection
        Point a = this.p1;
        Point b = this.p2;
        Point c = l.p1;
        Point d = l.p2;
        Point pIntersection = null;
        
        // if denominator == 0 , two lines are parallel  
        double denominator = (b.y - a.y) * (d.x - c.x) - (a.x - b.x) * (c.y - d.y);  
        if (denominator == 0) {  
            throw new IllegalArgumentException("Lines don't intersect!"); // parallel!  
        }  
        
        // calculate the point of intersection
        double x = ((b.x - a.x) * (d.x - c.x) * (c.y - a.y)   
                   + (b.y - a.y) * (d.x - c.x) * a.x   
                   - (d.y - c.y) * (b.x - a.x) * c.x) / denominator;
        double y = -((b.y - a.y) * (d.y - c.y) * (c.x - a.x)   
                   + (b.x - a.x) * (d.y - c.y) * a.y   
                   - (d.x - c.x) * (b.y - a.y) * c.y) / denominator;  
        
        // check this point is on both lines or not
        if (
                (x - a.x) * (x - b.x) <= 0 && (y - a.y) * (y - b.y) <= 0   // this point is on this line
             && (x - c.x) * (x - d.x) <= 0 && (y - c.y) * (y - d.y) <= 0   // this point is on other line 
           ) {
            pIntersection = new Point(x, y);
        } else {
            throw new IllegalArgumentException("Lines don't intersect!"); // point not on either line
        }
        
        return pIntersection;
                
    }