def lineLineIntersection(p0, p1, p2, p3):
 A1 = (p1[1] - p0[1])
 B1 = (p0[0] - p1[0])
 C1 = ((A1 * p0[0]) + (B1 * p0[1]))
 A2 = (p3[1] - p2[1])
 B2 = (p2[0] - p3[0])
 C2 = ((A2 * p2[0]) + (B2 * p2[1]))
 det = ((A1 * B2) - (A2 * B1))
 if (det == 0):
  return p0
 return [(((B2 * C1) - (B1 * C2)) / det), (((A1 * C2) - (A2 * C1)) / det)]

def lineLineIntersection ( p0 , p1 , p2 , p3 ) : A1 = ( p1 [ 1 ] - p0 [ 1 ] ) B1 = ( p0 [ 0 ] - p1 [ 0 ] ) C1 = ( ( A1 * p0 [ 0 ] ) + ( B1 * p0 [ 1 ] ) ) A2 = ( p3 [ 1 ] - p2 [ 1 ] ) B2 = ( p2 [ 0 ] - p3 [ 0 ] ) C2 = ( ( A2 * p2 [ 0 ] ) + ( B2 * p2 [ 1 ] ) ) det = ( ( A1 * B2 ) - ( A2 * B1 ) ) if ( det == 0 ) : return p0 return [ ( ( ( B2 * C1 ) - ( B1 * C2 ) ) / det ) , ( ( ( A1 * C2 ) - ( A2 * C1 ) ) / det ) ]
return the intersection of the infinite line trough points p0 and p1 and infinite line trough points p2 and p3 .