|
|
Tor Olav Kristensen wrote:
>
> 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
Changing the last expression in this macro to:
vlength(pP - pA + max(0, min(ss, 1))*vL)
or
vlength(pP - (ss >= 1 ? pB : (ss <= 0 ? pA : pA + ss*vL)))
also seems to work.
Tor Olav
--
mailto:tor### [at] hotmailcom
http://www.crosswinds.net/~tok/tokrays.html
Post a reply to this message
|
|