Skip to content
Snippets Groups Projects
Commit c23d0f86 authored by Malte Nyhuis's avatar Malte Nyhuis
Browse files

implement line_intersection

parent 0e68a038
No related branches found
No related tags found
No related merge requests found
......@@ -11,7 +11,7 @@ from scipy.spatial.distance import squareform, pdist
import sys
import math as m
import scipy
def calc_largedistant_idx(x_koords, y_koords):
"""
......@@ -231,3 +231,20 @@ def lineseg_dist(p, a, b):
return np.hypot(h, np.linalg.norm(c))
def line_intersection(point_a1, point_a2,
point_b1, point_b2):
def det_2d(a, b):
return a[0] * b[1] - a[1] * b[0]
xdiff = (point_a1[0] - point_a2[0], point_b1[0] - point_b2[0])
ydiff = (point_a1[1] - point_a2[1], point_b1[1] - point_b2[1])
div = det_2d(xdiff, ydiff)
if div == 0:
return None
d = (det_2d(point_a1, point_a2), det_2d(point_b1, point_b2))
x = det_2d(d, xdiff) / div
y = det_2d(d, ydiff) / div
return x, y
......@@ -166,3 +166,12 @@ def test_vecAngle():
b = np.array([0, 1, 0])
angle = vecAngle(a, b)
assert angle == np.pi / 2
def test_line_intersection():
import numpy as np
from ntrfc.utils.math.vectorcalc import line_intersection
intersect = line_intersection((-1,0),(1,0),
(0,-1),(0,1))
assert all(intersect==np.array([0,0]))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment