website articles
thinking with quaternions
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 useful 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 (coming from an Euler/Verlet integration)? Or when we just want to blend more than two quaternions 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 quaternion. As we know, a quaternion has one real component and three imaginary component. 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 cosine of a given (half-)angle and the vector v to be a normalized vector scaled by the sine of that same (half-)angle.

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

we have that


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 quaternion represents a 3D rotation around the axis a by an angle of alpha. And 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 two rows of the following table:

We can now easily convert any angular operation that we want to perform into the correct quaternion operations. Just replace additions/subtractions 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 operations (ala Laplace Transform)... Actually, there is a reason for this, and it is that quaternions are a generalization of complex numbers, and as such normalized quaternions are generalization of pure complex exponentials and thus the logarithmic relationships come apparent. Actually, if we have the following normalized quaternion

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