Forums.ATC.no

Teknisk => Generelt teknisk => Emne startet av: ATC på 27. ſeptember 2008, 18:24 pm

Tittel: Math: How to normalize a vector
Skrevet av: ATC27. ſeptember 2008, 18:24 pm
When dealing with 3D lighting or rotation quaternions, it is sometimes useful to normalize a vector; that is to recalculate the vector so that its magnitude becomes 1
Tittel: [Solved] Math: How to normalize a vector
Skrevet av: ATC27. ſeptember 2008, 18:24 pm
Divide each axis by the vector magnitude:

magnitude = sqrt( v[0]*v[0] +  v[1]*v[1] + v[2]*v[2] );
v[0] = v[0] / magnitude;
v[1] = v[1] / magnitude;
v[2] = v[2] / magnitude;