Distance between a point and a given line segment
I’m working on line simplification algorithms,I choose ramer douglas peucker algorithm, I found this python implementation:https://github.com/fhirschmann/rdp but I didn’t understand how they calculate the distance between a point and a line segment in (pldist function) can anyone give me more details and explain to me how this function do.
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(np.equal(start, end)):
return np.linalg.norm(point - start)
return np.divide(
np.abs(np.linalg.norm(np.cross(end - start, start - point))),
np.linalg.norm(end - start))
user25018201 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.