UrbanFlow / backend /geometry.py
Subh775's picture
restored to the safe state
a018ed7
Raw
History Blame Contribute Delete
412 Bytes
import numpy as np
def _side(p, a, b):
return np.sign((b[0] - a[0]) * (p[1] - a[1]) - (b[1] - a[1]) * (p[0] - a[0]))
def _point_to_segment_dist(px, py, ax, ay, bx, by):
A = np.array([ax, ay], dtype=float)
B = np.array([bx, by], dtype=float)
P = np.array([px, py], dtype=float)
AB = B - A
t = np.clip(np.dot(P - A, AB) / np.dot(AB, AB), 0, 1)
return np.linalg.norm(P - (A + t * AB))