Created
May 8, 2018 05:29
-
-
Save geohot/3153fd8f5588d6608fe6458236c70535 to your computer and use it in GitHub Desktop.
Lines in homogeneous coordinates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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