Last active
July 5, 2018 10:56
-
-
Save oisincar/a41cf965ab4c51ae6e06b01078f7e4c9 to your computer and use it in GitHub Desktop.
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
import numpy as np | |
def main(): | |
print intersectLines([0.,2.], [1.,1.], [3.,3.], [-1., -5.]) | |
def intersectLines(s1, e1, s2, e2): | |
# Append 1 to all points. Make them (x, y, 1) | |
s1, e1, s2, e2 = [np.append(p, 1) for p in [s1, e1, s2, e2]] | |
# Equations of lines :O! | |
# (a, b, c) in: ax + by + c = 0 | |
l1 = np.cross(s1, e1) | |
l2 = np.cross(s2, e2) | |
# Intersection (:O :O) | |
# (kx, ky, k). | |
# If k is 0, then no intersection/ intersection at 'infinity' (:O) | |
kx, ky, k = np.cross(l1, l2) | |
return [kx/k, ky/k] | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment