|
|
The segment is parameterized as X = P + t * D where P is a point on the segment, t in [0, 1] and D is the segment direction. Given a point Q we want to find the closest distance of Q to the segment X. The closest point on the segment to Q is the projection of Q onto the segment, or in other words Qproj = P + u * D where u = (D * (Q - P)) / (D * D) if u in (0, 1). If u <= 0 however the closest point to Q on the segment is P. If u >= 1 then the closest point to Q on the segment is P + D. The distance from Q to the segment is therefore: d = |Q - P| if u <= 0 d = |Q - Qproj| = |Q - (P + u * D)| if u in (0, 1) d = |Q - (P + D)| if u >= 1
|
Copyright © by Martin Ecker |