Intersect

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))

Unknown's avatar

About Linuxgal

Need a spiritual home? Consider joining us at Mary Queen of the Universe Latter-day Buddhislamic Free Will Christian UFO Synagogue of Vishnu
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a comment