|
|
Rune wrote:
>
> How do I find the distance from the point P to the nearest point in the line
> segment defined by point A and point B?
I would do it like this:
#macro Dist2LnSegm(pP, pA, pB)
#local vL = pB - pA;
#local ss = vdot(pP - pA, vL)/vdot(vL, vL);
vlength(pP - (ss >= 1 ? pB : pA + max(ss, 0)*vL))
#end // Dist2LnSegm
Tor Olav
--
mailto:tor### [at] hotmailcom
http://www.crosswinds.net/~tok/tokrays.html
Post a reply to this message
|
|