Skip to content

Instantly share code, notes, and snippets.

@geohot
Created May 8, 2018 05:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geohot/3153fd8f5588d6608fe6458236c70535 to your computer and use it in GitHub Desktop.
Save geohot/3153fd8f5588d6608fe6458236c70535 to your computer and use it in GitHub Desktop.
Lines in homogeneous coordinates
# homogenous line from two points (this isn't on the internet...)
line = [0,0,0]
line[0] = (f1[1] - f2[1]) * (f1[1] * f2[0] - f1[0] * f2[1])
line[1] = (f1[0] - f2[0]) * (f1[0] * f2[1] - f1[1] * f2[0])
line[2] = (f1[0] * f2[1] - f1[1] * f2[0]) * (f1[1] * f2[0] - f1[0] * f2[1])
line = np.array(line)
# line intersection (https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection#Using_homogeneous_coordinates)
p = np.array([l1[1] * l2[2] - l2[1] * l1[2], l2[0] * l1[2] - l1[0] * l2[2], l1[0] * l2[1] - l2[0] * l1[1]])
p /= p[2]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment