2021-04-21 10:45:34 +02:00
|
|
|
def ccw(A, B, C):
|
|
|
|
return (C[1] - A[1]) * (B[0] - A[0]) - (B[1] - A[1]) * (C[0] - A[0]) > 1e-12
|
2021-01-14 17:10:03 +01:00
|
|
|
|
|
|
|
|
2021-04-21 10:45:34 +02:00
|
|
|
def intersect(A, B, C, D):
|
2021-05-18 15:27:08 +02:00
|
|
|
"""
|
|
|
|
Checks whether line segments AB and CD intersect
|
|
|
|
"""
|
2021-04-21 10:45:34 +02:00
|
|
|
return ccw(A, C, D) != ccw(B, C, D) and ccw(A, B, C) != ccw(A, B, D)
|
2021-01-14 17:10:03 +01:00
|
|
|
|
|
|
|
|
2021-04-21 10:45:34 +02:00
|
|
|
def check_self_collision(line_points):
|
2021-06-24 15:52:21 +02:00
|
|
|
"""Checks whether line segments and intersect"""
|
2021-04-21 10:45:34 +02:00
|
|
|
for i, line1 in enumerate(line_points):
|
|
|
|
for line2 in line_points[i + 2:, :, :]:
|
|
|
|
if intersect(line1[0], line1[-1], line2[0], line2[-1]):
|
|
|
|
return True
|
|
|
|
return False
|