How can I optimize vector normalization in a Molecular Modeling
program?
Andomar
andomar at brotherrobot.org
Tue Nov 9 00:15:37 EST 1999
The optimizations I can think of:
VTYPE length;
length = v[0]*v[0] + v[1]*v[1] + v[2]*v[2];
if( length < 1.00001 && length > 0.99999 )
return true; // vector is already normal.
length = sqrt( length );
v[0] /= length;
v[1] /= length;
v[2] /= lenght;
return true;
The check for already-normalness will speed up
things if the program tries to normalize vectors
more than once. (You can't just temp == 0.0
because floats aren't exact.)
More information about the Molmodel
mailing list