Quaternion and normalization

前端 未结 6 1409
遇见更好的自我
遇见更好的自我 2020-12-23 12:34

I know that quaternions need to be normalized if I want to rotate a vector.

But are there any reasons to not automatically normalize a quaternion? And if there are,

6条回答
  •  独厮守ぢ
    2020-12-23 13:01

    Funnily enough, building rotation matrices is one operation where normalizing quaternions is NOT needed, saving you one sqrt:

    M = [w*w+x*x-y*y-z*z, 2*(-w*z+x*y),    2*(w*y+x*z);
         2*(w*z+x*y),     w*w-x*x+y*y-z*z, 2*(-w*x+y*z);
         2*(-w*y+x*z),    2*(w*x+y*z),     w*w-x*x-y*y+z*z] / (w*w+x*x+y*y+z*z)
    

    (in a MATLAB-ish notation) for the quaternion w+x*i+y*j+z*k.

    Moreover, if you are working with homogeneous coordinates and 4x4 transformation matrices, you can also save some division operations: just make a 3x3 rotation part as if the quaternion was normalized, and then put its squared length into the (4,4)-element:

    M = [w*w+x*x-y*y-z*z, 2*(-w*z+x*y),    2*(w*y+x*z),     0;
         2*(w*z+x*y),     w*w-x*x+y*y-z*z, 2*(-w*x+y*z),    0;
         2*(-w*y+x*z),    2*(w*x+y*z),     w*w-x*x-y*y+z*z, 0;
         0,               0,               0,               w*w+x*x+y*y+z*z].
    

    Multiply by a translation matrix, etc., as usual for a complete transformation. This way you can do, e.g.,

    [xh yh zh wh]' = ... * OtherM * M * [xold yold zold 1]';
    [xnew ynew znew] = [xh yh zh] / wh.
    

    Normalizing quaternions at least occasionally is still recommended, of course (it may also be required for other operations).

提交回复
热议问题