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).