Skrevet av Emne: Math: How to normalize a vector  (Lest 4299 ganger)

ATC

  • Gjest
Math: How to normalize a vector
« på: 27. ſeptember 2008, 18:24 pm »
  • [applaud]0
  • [smite]0
  • 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



    ATC

    • Gjest
    [Solved] Math: How to normalize a vector
    « Svar #1 på: 27. ſeptember 2008, 18:24 pm »
  • [applaud]0
  • [smite]0
  • 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;