% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/R-trajectory.R
\name{point_segment_distance_vec}
\alias{point_segment_distance_vec}
\title{Point-to-segment distance (vectorized)}
\usage{
point_segment_distance_vec(px, py, ax, ay, bx, by)
}
\arguments{
\item{px, py}{Numeric vectors (or scalars) giving the x/y coordinates of the
query point(s).}

\item{ax, ay}{Numeric scalars giving the x/y coordinates of endpoint A.}

\item{bx, by}{Numeric scalars giving the x/y coordinates of endpoint B.}
}
\value{
A numeric vector of distances, with length equal to
  `max(length(px), length(py))` (after R's usual vector recycling rules).
}
\description{
Computes the Euclidean distance from one or more points `(px, py)` to the
line segment defined by endpoints `A(ax, ay)` and `B(bx, by)`. The projection
is clamped to the segment (i.e., `pos_on_seg` is restricted to `[0, 1]`).
}
\details{
Let `v = B - A` and `pos_on_seg = ((P - A) · v) / ||v||^2`. The closest point
on the
infinite line is `A + pos_on_seg v`; clamping `pos_on_seg` to `[0, 1]` yields
the closest point
on the segment.

If `A` and `B` are identical (`||v||^2 == 0`), the function returns the
distance from `P` to `A`.
}
\examples{
# Single point to a horizontal segment
point_segment_distance_vec(px = 1, py = 2, ax = 0, ay = 0, bx = 3, by = 0)

# Multiple points (vectorized)
px <- c(0, 1, 2, 3)
py <- c(1, 1, 1, 1)
point_segment_distance_vec(px, py, ax = 0, ay = 0, bx = 3, by = 0)

# Degenerate segment (A == B)
point_segment_distance_vec(px = c(0, 1), py = c(0, 1), ax = 0, ay = 0, bx =
0, by = 0)

}
