public static boolean onSegment(Point2d p1, Point2d p2, Point2d Q){
        
        
        if(Q.sub(p1).crossProduct(p2.sub(p1))== 0
                && Math.min(p1.x, p2.x)<=Q.x
                && Math.max(p1.x, p2.x)>=Q.x
                && Math.min(p1.y, p2.y)<=Q.y
                && Math.max(p1.y, p2.y)>=Q.y)
            return true;
        return false;
    }