Find the the point on a line segment (x1,y1) (x2,y2) that is closest to point (px,py).
Usage
ClosestPoint(px, py, x1, y1, x2, y2)
Arguments
px
x coordinate of point
py
y coordinate of point
x1
x coordinate of one end of a segment
y1
y coordinate of one end of a segment
x2
x coordenite of other end of a segment
y2
y coordinate of other end of a segment
Value
a point-pair (x,y)
Details
This function finds the the point on a line segment (x1,y1) (x2,y2) that is closest to point (px,py). If the line perpendicular to the
line segment does not intersect the segment, the function will return an end point of the segment, otherwise, it will return a point on the line segment where the perpendicular line intersects the segment.
ClosestPoint(1,10,2,0,5,0) #returns end point 2 0ClosestPoint(20,10,2,0,5,0) #returns other end point 5 0ClosestPoint(4.5,10,2,0,5,0) #returns closest point 4.5 0