segment intersections does not work, algorithm tbt

This commit is contained in:
2019-10-09 17:32:04 +02:00
parent 3b4e7cd6f8
commit 34734dd734
2 changed files with 123 additions and 15 deletions

34
trigo.py Normal file
View File

@@ -0,0 +1,34 @@
#!/usr/bin/env python
import math
def angle_to_vector(angle):
angle=angle*math.pi/180
return [math.cos(angle), math.sin(angle)]
def segments_intersection(line1, line2):
x1,y1 = line1[0]
x2,y2 = line1[1]
x3,y3 = line2[0]
x4,y4 = line2[1]
xdiff = (x1 - x2, x3 - x4)
ydiff = (y1 - y2, y3 - y4)
def det(a, b):
return a[0] * b[1] - a[1] * b[0]
div = det(xdiff, ydiff)
if div == 0:
return None
d = (det(*line1), det(*line2))
x = det(d, xdiff) / div
y = det(d, ydiff) / div
if min(x1,x2) <= x <= max(x1,x2) :
return x, y
return None
def distance(point1, point2):
return math.hypot(point1[0] - point2[0], point1[1] - point2[1])