segment intersections does not work, algorithm tbt
This commit is contained in:
34
trigo.py
Normal file
34
trigo.py
Normal 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])
|
||||
Reference in New Issue
Block a user