Closest points on two line segments
ID: closest-points-on-two-line-segments
For line segments and , , the squared Euclidean distance is a convex quadratic function on a square. Its minimum is either an admissible stationary point or a minimum on one of the four edges. Each edge minimum is a point-to-segment orthogonal projection, restricted to the interval. Testing these five candidates gives a complete algorithm; when the directions are parallel, the edge candidates suffice. Independently restricting both coordinates of the unconstrained stationary point is generally incorrect because the variables are coupled by .
New to topics? Read the docs here!