[ODE] Simulating Magnetism...

Jon Watte hplus-ode at mindcontrol.org
Tue Jan 11 16:17:13 MST 2005


> DistBetweenBodiesSquared = abs(
> 	pow(direction[0], 2) +
> 	pow(direction[1], 2) +
> 	pow(direction[2], 2)));


I would like to add that writing "direction[0]*direction[0]" will 
generate code that is significantly faster, and probably more 
accurate. The pow() function is one of the slower in the math 
library. You also don't need the abs(), because a real value when 
squared is never negative.

Also, if you want it to look all elegant-like, you'd just dot the 
direction vector with itself:

  DistBetweenBodiesSquared = dot3( direction, direction );

Which works out to the same thing.

Cheers,

		/ h+




More information about the ODE mailing list