Re: Distance point <=> straight line in space
- From: Daniel Kraft <d@xxxxxxxx>
- Date: Thu, 31 Jul 2008 17:53:03 +0200
Ben Bacarisse wrote:
V = (p2 - p1)/norm_squared(p2 - p1);According to the formula on MathWorld and to my tests, this should in
fact be a normalized vector, so not norm_squared here.
Do check again... I am highly fallible in such matters, but I've gone
back and can't see it myself. My suggestion is formula (6) from that
page and everything there is either a vector difference or involves
|...|^2. I divided out by |x2-x1|^2 and I can't see any actual
normalisation.
Their formula (6) is:
d^2 = (|x1 - x0|^2 * |x2 - x1|^2 - ((x1 - x0) * (x2 - x1))^2) /
|x2 - x1| ^2
= |x1 - x0|^2 - ((x1 - x0) * (x2 - x1))^2 / |x2 - x1|^2
= |x1 - x0|^2 - ((x1 - x0) * (x2 - x1) / |x2 - x1|)^2
= norm_square (Q) - (Q * V)^2, where V = (x2 - x1) / |x2 - x1|, single normalization.
Cheers,
Daniel
Thanks for this suggestion, it works and gives around 20% speed-up,
quite nice :)
Excellent. 20% is what one would expect from saving 20% of the
operations, but it is good when practise follows theory.
--
Done: Arc-Bar-Sam-Val-Wiz, Dwa-Elf-Gno-Hum-Orc, Law-Neu-Cha, Fem-Mal
Underway: Cav-Dwa-Law-Fem
To go: Cav-Hea-Kni-Mon-Pri-Ran-Rog-Tou
.
- References:
- Distance point <=> straight line in space
- From: Daniel Kraft
- Re: Distance point <=> straight line in space
- From: Ben Bacarisse
- Re: Distance point <=> straight line in space
- From: Daniel Kraft
- Re: Distance point <=> straight line in space
- From: Ben Bacarisse
- Distance point <=> straight line in space
- Prev by Date: Re: sort algorithm
- Next by Date: Re: Distance point <=> straight line in space
- Previous by thread: Re: Distance point <=> straight line in space
- Next by thread: Re: Distance point <=> straight line in space
- Index(es):