ClosestPoint: Find Closest Point

View source: R/ClosestPoint.R

ClosestPointR Documentation

Find Closest Point

Description

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

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.

Value

a point-pair (x,y)

Note

Uses LineMagnitude, also supplied by the pathmapping package.

Author(s)

Shane T. Mueller and Brandon Perelman

References

See Mueller et al., (2016). https://sites.google.com/a/mtu.edu/mapping/

See Also

LineMagnitude, DistancePointSegment

Examples

ClosestPoint(1,10,2,0,5,0)    #returns end point 2 0
ClosestPoint(20,10,2,0,5,0)   #returns other end point 5 0
ClosestPoint(4.5,10,2,0,5,0)  #returns closest point 4.5 0



stmueller/pathmapping documentation built on Nov. 13, 2023, 12:39 p.m.