Distance point <=> straight line in space
- From: Daniel Kraft <d@xxxxxxxx>
- Date: Wed, 30 Jul 2008 20:43:33 +0200
Hi,
in a program, I've got a straight line in space defined by two points (p1 and p2) on it, and a set (~ 10000) points q_i in space. Then I need to calculate for each of those points the distance to the straight. At the moment I'm doing it like this:
vector g = normalized (p2 - p1) // Find normalized direction
for i = 1 to n
distance_i = norm (cross_product (p2 - q_i, g))
I believe this formula is fairly straight-forward (a single cross-product and a norm); unfortunatelly, my program spents a large amount of time (~ 95% of total runtime) in this routine and the current duration is unacceptable.
Is there a better approach I could take to do this calculation that requires less operations? The output of gcc -O3 seems already reasonably optimized, i.e., the cross-product and norm calculation is fully inlined. I don't think hand-optimized inline-assembly could help here much, right?
Thanks,
Daniel
--
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
.
- Follow-Ups:
- Re: Distance point <=> straight line in space
- From: Bartc
- Re: Distance point <=> straight line in space
- From: James Dow Allen
- Re: Distance point <=> straight line in space
- From: Ben Bacarisse
- Re: Distance point <=> straight line in space
- From: Pascal J. Bourguignon
- Re: Distance point <=> straight line in space
- Prev by Date: Loop-dedicated benchmark suites?
- Next by Date: Re: Algorithm to achieve this result?
- Previous by thread: Loop-dedicated benchmark suites?
- Next by thread: Re: Distance point <=> straight line in space
- Index(es):
Relevant Pages
|