Quaterinons? Yet another article about quaternions for rotations in 3D graphics? In 2006?! ... not really. Well, not completely, I don't
want to replicate the information that can be so easily found by typing "quaternion 3d rotation" in google. Instead, the aim of this article is just to
summarize and share a few usefull ideas I found while working with quaternions in some projects. Actually these came when trying to use quaternions for
several rotation operations. Many programmers do copy and paste the famous lerp() and slerp() functions for quaternions,
widely used for key-frame interpolation, and never mind about the origin of the functions; and actually it's normally not a problem because armed
with these two, plus a quat2matrix() and euler2quat() functions we are done. Or may be not? What happens when we have a
physics engine and we want to "increment" and angular transformation of an object by an incremental rotation (caoming from an Euler/Verlet integrarion)?
Or when we just want to blend more thatn two quaterions and we cannot use the lerp()? Ok, that what we will solve in this small article.
Let's go into business.
Let q be a quaterion. As we know, a quaternion has one real component and three imaginary component. All this four components x,
y, z and w are orthogonal to each other. The three imaginary units i, j and
k are equal to the square root of minus one, as usual. However, what we are interested in for 3D graphics is in the axis/angle notation
of the quaternion. By packing together the three imaginary components we can think on the quaternion as a real value w plus a 3D vector
v. To get our axis/angle notation we just have to impose to our quaternion that the real component w is the cosinus of a
given (half-)angle and the vector v to be a normalized vector scaled by the sinus of that same (half-)angle.

Such a quaternion following the last restiction can be checked to be normalized, since by the definition of norm/modulus of a quaterion

we have that

so

Now, the interesting property comes into the game. The power of a quaternions happens to be like this

What results in the following interpretation: self-multiplying a quaternion t times is the same as multiplying the angle by t (even
if I find this interpretation a bit tricky for non integer values of t...). We can now start to see why quaternions are used for angular
operations. Actually, we know a normalized quaterion represents a 3D rotation around the axis a by an angle of alpha.
Actually, we know that concatenating two rotations can be done by multiplying the two corresponding quaternions. Hence what we have to remember is
just the first to rows of the following table:

We can now easilly convert any angular operation that we want to perform into the correct quaterion operation. Just replace additions/substractions by
multiplications/divisions, and multiplications/divisions by powers/roots, and we are done. This relationship between angle and quaternion operations
quite resembles the relationship between linear and logarithmical operatoins... Actually, there is a reason for this, and it is that quaterions are
a generatlization of complex numbers, and as such normalized quaterions are generalizaton of pure complex exponentials and thus the logarithmic
relationships come apparent. Actually, if we have the folloing normalized quaterion

and we make the axis equal to the real axis x=(1,0,0), we have

|