Have you been hearing the term âQuaternion Rotationsâ in Blender and wondered what they are -- or even how to control them?
What this article covers
So...what are quaternion rotations?
Quaternions are 3D rotations performed by the multiplication of quaternions.
Got it? Yeah, probably not...
Before explaining how these rotations work, Â we'll need to define a few terms first.
Before we begin...
1) In computers, everything is represented by numbers.
Numbers make up everything we do on computers (including Blender). Whether it is a character, an operation, the position of a pixel on your screen, a color... or even a number. Blender will see all operations and input as numbers.
2) Any point in 3d space has three coordinates
A single point P has coordinates x, y and z. For example, (3.0, 0.73, 2.5). But these coordinates can also represent a 3-dimensional vector.
A number in the form of a âtripleâ (a, b, c) can represent a simple point, but it could also be another 'type'.
A 'type' refers to a point, but also a color, or a vector.Â
One type can even change into another, which is what we call 'type-switching'.Â
3) A triple can represent a vector type
You may remember vectors from high school maths: a vector is like an arrow, with a direction and a length, but not a fixed position.Â
In our example, vector (3.0, 0.73, 2.5) is an arrow going from the origin (0, 0, 0) to point (3.0, 0.73, 2.5).Â
It can be placed anywhere in 3D space, it is still considered the same vector, just with a different triple.
You can rotate or scale a vector and its coordinates will change accordingly.
Internally, Blender will see all these numbers as âtriplesâ. Â
4) Blender uses triples to determine various operations
Knowing this, we can do some cool things like use a Vector output to drive the color of a shader.
And because everything is a number itâs also possible to do completely ridiculous and meaningless things: like determining the length of color. Â What!? Â A colour can have a length? Â Well a color to Blender is just a number and so yes, you can find the length of that number.
 In this example I am taking the cross product of a point in space and a Noise Texture, and plugging the result into an emission shader. Did I mention you can do completely ridiculous things with numbers?
5) Quaternions = Hamilton numbers
In the rest of this article, I am going to do something outrageous and call quaternions âHamilton numbersâ. Firstly, I think this sounds more friendly, less intimidating. And secondly, this way you are less likely to forget that a quaternion is a number.Â
Understanding Complex Numbers (in 2D)
Hamilton numbers are the best way to rotate in 3d space - and we will get to them shortly, but for simplicity, first, let's look at 2D.
(Watch out: extreme âtype-switchingâ ahead!)
Letâs say we have a 2-dimensional plane, called 'real plane', with a point that we want to rotate around the Origin.
(If we can do that, we can rotate as many points as we like around any point on the plane.)
Now, we'll create a (linked) âcopyâ of this plane and place it perpendicular to our real plane. The copy is called a 'complex plane' (for historical reasons, not because of its complexity! We might as well call it the relax plane...):
Everything that happens in the real plane also happens in the complex copy -- and vice versa.
ďżź
For every point (a, b) on our real plane, there is a point on the complex plane.Â
This point represents a complex number (a+bi). The i portion of this is called an âimaginary numberâ, where  i² = -1.
Quick recap: Now we've introduced complex numbers (points on our complex plane) and an imaginary number i.
Now, multiplying two points doesnât make much sense, but we can easily multiply two numbers (even when they are âcomplexâ).Â
Example 01 with complex numbers in 2d
For a point P(a, b) in our real plane, there is a corresponding point P(a+bi) in the complex plane.
If we multiply this point by i [this is the complex number (0+1i)], we get:Â
Now comes the beautiful part: if we look at this graphically, we can see that we just rotated the vector (a, b) by 90° (around the Origin):
Thereâs one thing to note about this example.
We multiplied our vector by i, which has a length of 1. Â That's because it is a vector that moves exactly 1 unit in a given direction.Â
If we would have multiplied by 2i, we still would have rotated 90°, but also scaled vector P by a factor 2.
There's another way of seeing this.Â
The same operation would be done if we multiplied two vectors by adding their angles and multiplying their lengths.Â
So we will make it a convention to only multiply by vectors of length 1, that is: by numbers, whose corresponding points lie on the unit circle. When we add the angles and multiply the length by 1, we will only get the rotation, without any scaling.
Example 02 with complex numbers in 2d
This works for any angle; we take the unit vector in the complex plane that makes the desired angle with the positive X-axis and multiply the corresponding number by the number belonging to the point we want to rotate. Put the result back into the real plane and Bobâs your uncle.
If we call the angle of rotation , we can also write point C as: (cos, sin) and the number as: (cos+isin). This will become especially useful in 3D.Â
If a number lies on the unit circle, meaning it corresponds to  a  vector of length 1, we say the number has a Norm 1. (As numbers do not have a length. This is the equivalent of length for vectors and distance (to origin) for points.)
Example 03 with complex numbers in 2d
Here is an important term:Â
if we have a complex number then we callits complex conjugate.
(Here I use the notation C'Â to indicate the conjugate of C, but there are other notations that you may encounter...)
When we multiply a complex number P by some complex number C of Norm 1, we rotate by a certain angle θ.
If we after that multiply again, but this time by the conjugate of C, we rotate by an angle of (360°-θ) and thereby return to the original place of P.
As a special case: if P is an imaginary number, meaning its real part is 0, for instance: then is also an imaginary number for any complex number C. Although this sounds trivial here, it will be extremely important when dealing with 3D rotations!Â
Multiplications of this form are called sandwich multiplications, for (I hope) obvious reasons.
OK this is how it works in 2d, and you can stop reading here, knowing that a similar thing occurs in 3d space, though it gets way more complex. If you want to dive into that, keep on reading, but put on your safety helmet first!
Understanding rotations in 3d
Still reading? Â Safety helmet on? Good. Letâs see if we can also rotate in 3D, by multiplying special numbers.
Spoiler alert: we can.
The first idea, to use special numbers of the form (a+bi+cj) doesnât work. (Mathematicians have been trying this for quite some time without successâŚ)
The Irish mathematician Sir William Rowan Hamilton (whilst walking along the Royal canal in Dublin, not at all paying attention to what his wife was telling, about how her friend had been wearing this outrageously colored dress at last nightâs soiree) discovered that we need special numbers of the formwhere These are what I shall refer to as Hamilton numbers. (Remember that I use that as a sort of euphemism for quaternions; they are not actually called that.)
Now, imagine a (linked) âcopyâ of our beloved 3D space. In your mind, place this copy perpendicular to our 3D space (donât worry if you canât do this. Maybe you can imagine two paralel 3 dimensional worlds...). Â We shall call this the imaginary (3 dimensional) world. Every point in our real world has a corresponding point in this imaginary world. And everything that happens in the imaginary world, happens in the real world and vice versa. Â Just like in the Netflix series Stranger Things!
Â
Hereâs a sloppy version of how quaternion rotations work...
Under the hood, Blender takes the vector of rotation, divides it by its length and puts it in the imaginary world, along with the object that needs to be rotated, then rotates the object twice by a multiplication sandwich of Hamilton numbers; the first part of the sandwich creates a Hamilton number with a (usually) non-zero real part, meaning we now have one foot in the real world, while our other three limbs are still in the imaginary world. The second part of the sandwich multiplication makes the real component zero again, so that we are completely back in the imaginary world. Then, Blender puts the rotated object back into the real world (and whoâs your uncle?).
By multiplying twice, we also rotated twice (in the same direction!), that is why we need each of those rotations to be half the angle we want the 3D rotation to be.Â
And although I donât recommend ever trying to visualize what is happening in more than 3 dimensions, hereâs an exclusive âbehind the scenesâ of what happens when we project the 4 dimensional Hamilton Space onto our 3 dimensional world and make a quaternion rotation of 90° around the (1, 1, 1) vector. Be aware that this is like a 3 dimensional âshadowâ of what is happening in 4D; this is not what it would look like in 4D.
In Blender, if we set the rotation mode to quaternion we get the 4 fields: W, X, Y and Z. Important to notice here is, that the angle of rotation is contributing to all four; to be precise, if the angle of rotation is θ, and the unit vector around which we want to rotate is (a, b, c), then:
[As we have set  and
Just to be clear: that rotation vector is placed at the objectâs origin. If the object is rotated around some other line, then that is done by rotation around the objects origin AND a translation.
You don't actually have to fill in those fields by hand, but it is good to know what is happening.Â
Here is some of the math. You also don't need to do this manually, but I think it is a good idea to at least have seen it once. However, if you are feeling brave you can also try this at home! (It looks much more complicated than it actually is)
Getting Stuck into the Numbers: Quartnenions in 3d
As in the case of the complex numbers (...which completely sounds like a lost Sherlock Holmes novel) if we have a Hamilton number then its conjugate isÂ
Furthermore, we will need the following formulas for multiplication;Â
With these rules multiplying any two Hamilton numbers is now super easy (apart from the many terms you need to keep track of...).
There are a few things I would like to point out here:Â
Let's say we want to multiply above-mentioned Hamilton number h with another Hamilton number p. That is hp, not ph.  The order matters here as mentioned above.
So letâs say
Like I said before, this results in a (usually) non-zero real component, namely:Â
The imaginary components after this multiplication hp are:Â
Now we are going to multiply this by the conjugate of
(So, the total multiplication is:Â )
The resulting real part is now:Â
 You can see how this works and maybe you can 'feel' how the property etc. accounts for the fact that âleft-multiplyingâ by h results in the same rotation as âright- multiplyingâ by h'.Â
And if you are not convinced, you can carry out the complete sandwich multiplication yourself.
That is why we use half the angle in the rotation. Because we have to multiply twice!
Before you Go: Take-Home Challenge
Your head is probably spinning by now, but I am not completely finished with you just yet; hereâs a little challenge:
Open Blender, delete the default Cube, add a Monkey and switch the rotation mode to Quaternion (I know, not much of a challenge yet for most of you, but waitâŚ)
Fill in the W, X, Y, Z fields, so, that Suzanne rotates 180° around the axis that goes through (0, 0, 0) and (3, 4, 5).
Maybe try other angles and axes and, if you feel confident, find the axis and angle when:
And you might want to confirm that: (or very close to 1, due to rounding errors).
Thatâs all folks! Thatâs all there is to it. Câest simple comme bonjour. (itâs as simple as âhelloâ)
I hope you more or less âgetâ quaternion rotations by now and I would like to end with these wise words: the more you think about it, the more sense it will make.Â
The part:
"
p = (0 + xi + yj + zk)
Like I said before, this results in a (usually) non-zero real component, namely:
(0a+(bx)i^2 + (cy)j^2 + (dz)k^2) = (0-bx-cy-dz)
"
I don't understand how we got the 2nd equation.
We went from defining "p" to suddenly the 2nd equation.
Is that just the result of "h*p" and we skipped all the steps?
blanchsb I'm glad you find hose video's helpful. I haven't seen 3Blue1Brown, because I don't like his way of explaining (I like my coffee black and my math abstract), but the other link I knew already and it is indeed great (one of the best I've seen on this topic).
The only thing is they put too much emphasize on visualizing and that is something I tried to avoid as much as possible, because I don't agree with: "...and that understanding complex multiplication is made easier when understanding how they rotate points on the plane." It is necessary to know about the connection between multiplication and rotation, but but it doesn't make it easier (for me!!!).
Anyway, looking at quaternions in different ways can be really good. Just remember that we are all talking about the exact same thing, although it might look different sometimes.
spikeyxxx I am getting closer to understanding quaternions a little better. I watched a cool video by YouTube instructor 3Blue1Brown about it as he covers the topics in 2 videos.
But then I came across what I can only say is the most impressive interractive video lesson I have ever seen on mathematics that this guy and his cohort came up with:
I'll post a link below but feel free to google it if you are afraid of clicking links. It is amazing.
https://eater.net/quaternions/
Great to see an article of yours, spikeyxxx !
spikeyxxx Thanks for creating this article. Quaternions mess me up sometimes.
coyohti I think your friend is right :)
me1958424 it's not only to prevent Gimbal Lock....
suppose you have a rotation around some axis by a certain angle followed by another rotation around a different axis by some other angle.....what would be the total rotation???
Using quaternions this would just be: multiplying the two 'Hamilton numbers'...( H2*H1* POINT*H1'*h2')....now you try this with Euler or Axis Angle rotations ;)
there are even more advantages...better interpolations and more...
spikeyxxx I had linked this to a friend of mine and she said, "That's the sort of thing you need to go into with a cup of tea and a snack. Really settle in." Next read-through I will be prepared. :D
wonderful technical explanation in a practical format!!
just imagine all of that going on just to prevent gimbal lock!!
Really great explanations, thanks a lot for taking the time!