Distance point <=> straight line in space



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
.



Relevant Pages

  • Re: Gravity, space-time, and black holes?
    ... a train car that can move forward and backward along a straight railroad. ... We can draw the train's worldline by plotting the ... then why does the distance between them decrease at an increasing rate as ... What will actually happen to the infalling astronaut, ...
    (sci.physics)
  • Re: The simplicity of relativity (for TomGee and others)
    ... >> the interior of a bowl, it still rolls in a straight line on the ... >> A boy sat next to a pigeon on a park bench in the city. ... >> east-west street if you like to mark the distance." ...
    (sci.physics)
  • Re: The simplicity of relativity (for TomGee and others)
    ... >> the interior of a bowl, it still rolls in a straight line on the ... >> A boy sat next to a pigeon on a park bench in the city. ... >> east-west street if you like to mark the distance." ...
    (sci.physics.relativity)
  • Re: Distance point <=> straight line in space
    ... calculate for each of those points the distance to the straight. ... k' => the offset of the line as it crosses the x axis ... C' => cos) - you may need to make sure you get the quadrature ...
    (comp.programming)
  • Re: OT: Re: Looking For Geodetic Python Software
    ... An airplane flies more-or-less in a straight line above that curvature. ... For sufficiently long airplane routes (where the ascent/descent distance is trivial compared to the overall horizontal distance traversed), a straight line path shorter than the over-earth path is possible. ...
    (comp.lang.python)