Solve for the intersection of two lines from four points with Python
#!/usr/bin/env python3
import sys,numpy as n
p,q,r,s=map(n.array,((float(sys.argv[i]),float(sys.argv[i+1])) for i in (1,3,5,7)))
M=n.c_[q-p,s-r]
d=n.linalg.det(M)
if abs(d)<1e-10:
print("Coincident" if abs(n.cross(q-p,r-p))<1e-10 else "Parallel")
else:
t,_=n.linalg.solve(M,r-p)
print(p+t*(q-p))
