
Project points onto line segments (Euclidean/planar geometry)
Source:R/calc_euclidean_detection_rate.R
project_points_simple.RdVectorized computation of the distance from each point in P to each
line segment defined by S (starts) and E (ends), and the distance
along the segment to the projection of the point.
Arguments
- s
An n x 2 matrix of segment start coordinates.
- e
An n x 2 matrix of segment end coordinates.
- p
An m x 2 matrix of point coordinates.
- m
Number of points (
nrow(p)).- n
Number of line segments (
nrow(s)).- v
e - s, precomputed segment vectors.- vv
rowSums(v^2), precomputed squared segment lengths.- clamp
If
TRUEconstrain the projected fraction to[0, 1]. IfFALSE(default) projections falling outside the segment are set toNA.- tol
Segments with squared length at or below this threshold are treated as having zero length (projected fraction set to 0).