You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 14, 2025. It is now read-only.
The current pldist function returns the distance between a point and the infinte line generated by two other points (i.e the distance to the orthogonal projection), which is incorrect. It should return the distance between a point and a line-segment.
def pldist(point, start, end):
"""
Calculates the distance from ``point`` to the line given
by the points ``start`` and ``end``.
:param point: a point
:type point: numpy array
:param start: a point of the line
:type start: numpy array
:param end: another point of the line
:type end: numpy array
"""
if np.all(start == end)):
return np.linalg.norm(point - start)
# normalized tangent vector
d = np.divide(end - start, np.linalg.norm(end - start))
# signed parallel distance components
s = np.dot(start - point, d)
t = np.dot(point - end, d)
# clamped parallel distance
h = np.max([s, t, 0])
# perpendicular distance component, as before
c = np.cross(point - start, d)
# use hypot for Pythagoras to improve accuracy
return np.hypot(h, c)