Quaternions
The Spherical Guide to Rotations

Lets start off by me clearly stating that I’m not a math guy and this is by no means going to explain everything there is to know about Quaternions and how they are calculated. What I will attempt to show is how they can be used and their advantages and disadvantages over using the tried and true Euler rotations.

So what is a Quaterion Rotation?

It might be best to discuss why we have Quaternions in the first place. A long time ago in a gallaxy far far.. oh wait, it was right here on earth a math guy named Leonhard Euler worked out a way to deal with rotations in 3D space. As it turns out this isn’t an easy thing to do. Euler had a great idea that lasts to this day and is called Euler rotations, how ever there are certain problems with it like having to deal with gimbal lock as it can cause all sorts of issues. The problem isn’t with the end rotation so much as getting to a from one rotation and another, as this is where the gimbal issues rear their ugly head. The cool thing about Quaternion rotations is they dont’ have axes so there is nothing to gimbal lock with.

The story goes that mathmaticians for a very long time were trying to solve these issues with Euler’s rotations but couldn’t come up with a good answer until William Rowan Hamilton in mid 1800’s, out walking with his wife had an epiphany and carved the solution into a bridge with a pen knife. There is a plaque there now that commemorates his solution. Funny thing is I have never had a plaque on any of the park benches I carved up with a pen knife.

Quaternion FormulaThe solution to the problems of Eulers rotations turns out to not be three values but four. A Quaternion (Quat) does not use axes like an Euler angle value does but instead uses a set of four values that describe a vector on a sphere and a single normalized angle around that vector.

To imagine what this looks like we can think of a sphere with a radius of 1, with a point at the center. From that center point imagine an arrow that stretches out and touches the surface of the sphere so that it has a length of 1. We can describe the point at which the arrow touches the sphere as a vector much like we do for a transform matrix vector value. The fourth value describes an angle around that arrow as a normalized value, meaning 0 to 360 degrees becomes 0 to 1.

How do you rotate a point and an angle?

In our spherical world (some still think it is flat, TA’s call them animators) we don’t rotate an axes but instead move a vector always making sure that it stays on the surface of the sphere, this will ensure that it remains as a Unit or Normalized vector with a length of one.

The numbers look a little strange at first when you see them and I have to say I don’t yet fully understand them my self as they are far more complex that what we are used to. Trying to work them out is sort of like drinking your first Pan Galactic Gargle Blaster which has been described as “having your brains smashed in by a slice of lemon wrapped round a large gold brick.” Douglas Adams

Object Aligned to World Rotation :
Object Rotated 180° around X :
Object Rotated 90° around X :
Object Rotated 180° around Y :
Object Rotated 180° around Z :

(quat 0 0 0 1)
(quat -1 0 0 0)
(quat -0.707 0 0 0.707)
(quat 0 -1 0 0)
(quat 0 0 -1 0)

 TCB?

No it isn’t what gets you high in pot or used as a household cleaner, it stands for Tension, Continuity, Bias and it is the tools that are used to control the in and out tangents for keys. 

The Key Info dialog in 3DS Max shows the settings that you have for each key, you can’t view function curves since they would make little sense as they look like a tangled mess of four values. There is a fair amount of control allowing for easing, over shoot creating linear transitions and much more. It just take a little time to wrap your head around it. 

In 3DS Max there is also a Rotation Windup option that allows for tracking of input from the user so it knows that you have done a full rotation between two keys. 

What are the advantages?

The advantages of using a Quat rotation over Euler angles is they don’t have axes so there is never a time that you can run into gimbal lock so say good bye to trying to untangle function curves so you don’t need up with a characters arm flying all over the place in between keys.

It is easy for instance to animate a ball rolling on the floor as it can be automated by calculating the angles needed for the Quat. Gimbal again can’t happen so you don’t run out of axes to go in the direction that you want.

Another example might be a gymnast doing a floor routine where they are flipping and spinning down the mate. Imagine doing this with Euler angles where you have to constantly deal with gimbal problems. The timing is fluid for the most part so there is limited need for accurately managing your tangents so a Quat value would work far better here.

What are the disadvantages?

There are a few and this is why animators don’t tend to like them. First off as I have pointed out there are no axes which means you can’t see the tangent of how a rotation is going from one key to the next. For this as explained above you have three spinners that control the flow. Not exactly artist friendly but then neither is gimbal lock.

Because of the way the values work there is no winding up of an axes so if you rotate an object 360° around a single axis or plane so the result is two keys, one on frame one and one on frame 20 and then scrub the time line you will notice that the object does not rotate at all and just stays put. This is because you have moved a vector from the top of the sphere and placed it back at the top of a sphere resulting in a vector that doesn’t move any where.

A similar problem can show up when you rotate an object around a single plane 180°. What might happen is the object will go the wrong direction and this is because the vector is starting at the top of the sphere and finding the shortest path to the bottom of the sphere. Remember there is no angle axes for it to know which way you wanted it to go, it will just take the shortest path from one point to another. To get an object to rotate a full 360° you need to rotate the objects in thirds around the sphere so you can control which way it is going between keys.

In closing

I can say this is the least accurate description of a Quaternion that you will ever see but I think it might help you understand why you might use one over a set of Euler angles. Most avoid it because they don’t know what it is and get very confused when they don’t see function curves. There are many cases in animation where far more time will be spent trying to run Euler filters and untangle curves then will be spend working with Quats. Another good trick is to use animation layers and blend in Quat rotations when you hit a section of animation that will be very difficult.