In earlier posts, I described how complex numbers can be used to rotate, scale, and translate the plane, how Clifford algebras can be used to rotate, scale, and translate the plane, and why I resorted to an awkward trick for the Clifford algebra rotations of the plane. In this post, I am going to explain what the quaternions are and describe how they can be used to represent a rotation in three-dimensional space.

### What are the quaternions

Okay, remember how we got the complex numbers? We needed something that was the square root of negative one.

Now, imagine that you are Sir William Rowan Hamilton. The year is 1843. It is springtime. You know how to use the complex numbers to represent points in the plane. And, you know that when you do that, you can use complex numbers to rotate, scale, and translate the points. That’s all well and good, but you don’t live in a two-dimensional world. How are you going to do the same sort of thing with three-dimensional space? How are you going to multiply triples

?

You spend months on this. If only you could say, How about I let there be another number that is different from (and from ) that has the same property that its square is negative one?

You fight with this for months. You try to represent a point with coordinates as . But, nothing you come up with makes any sense.

Your kids are harassing you, Daddy, did you figure out how to multiply triples yet?

You have to answer them every morning with a polite, No, not yet.

Then, you’re walking along the Royal Canal in Dublin. It’s mid-October already. My, how the year has flown by. Bam, it hits you. If you add a third number like and which is equal to , everything works out. You get so excited, that you carve your equations into a stone bridge over the canal:

Now, instead of trying to represent as , it is represented as . Immediately, this looks like an improvement. Before, things were not symmetric. Squaring something that was only in the x-direction was fundamentally different than squaring something that was only in the y- or z-direction because , but . Now, at least, there is no singled-out axis.

Let’s just explore the part for a minute. If we multiply both sides (on the right) by , we see that: . If, instead, we multiply by on the left, we see that . If we take that and multiply on the right by , we get . We’re going to show in a minute that . So, if take , , and in that order and take two in a row (wrapping around if needed), the product is the next one: , , and .

So, how do we show that ? Well, it’s pretty simple to show that . We already know that . So, . We know that , so . And, we know that , so . And, since we already know that , we have . We can use this, then to manipulate . . We can do a similar thing to show that .

This should look familiar from the the Clifford algebras. In the Clifford algebras, . Here, . It turns out that this is extra important in three-dimensions compared to two.

In two dimensions, if you rotate by an angle and then by and angle , it is the same thing as if you rotate by the angle and then by the angle . In three-dimensions, you have more options. In addition to picking the angle, you can also pick the axis of rotation. (Actually, for later on, it may be helpful to think of picking the plane parallel to which the rotation will take place rather than thinking of it as an axis.) In the picture at the right, the die in the back is the original position of a die. The die on the left is the result of rotating the original die a quarter turn on its left face (orange arrow) and then a quarter turn on its right face (blue arrow). The die on the right is the result of rotating the original die around its right face (blue arrow) and then its left face (orange arrow). As you can see, the resulting positions are different.

[Ugh… I just realized the free model of a die that I downloaded is not an actual, legal die. If it were, the opposite faces would sum to seven. Clearly, however, the two and the five are on adjacent faces of this die, as are the three and four, and thus also the one and six. Erf. So, you can’t repeat this experiment on your desktop unless you fabricate your own die. Sorry.]

Like the Clifford algebras and the complex numbers, addition and subtraction are simply adding and subtracting (respectively, of course) the corresponding parts.

Armed with the above identities, we have enough information to multiply together quaternions. Rather than do the full general case of , I’m going to do a simpler case to give you the flavor without wasting a ton of space in this article beating a horse that needn’t be beaten that much. Let’s just try: . We start with the distributive law, twice, and then combine like terms.

There is one other notation we’re going to need below. In the complex numbers, we used the notation to mean the number with the sign of its imaginary part reversed. So, if , then . With the quaternions, we are going to use to mean the number with the sing of *all of its imaginary parts* reversed. So, if , then .

### Transforming Space

Say you have some list of points in three-dimensional space: , , , . We are going to represent those as pure quaternions: , , , .

If we want to translate them all by two units along the x-axis, three units along the y-axis and five units along the z-axis, we can set and then add to each of our points: .

If we want to scale three-space out from the origin by a factor of seven, we can set and multiply each point by : .

Let’s say now, that we want to rotate our points parallel to some plane through the origin by an angle . The first thing we need to find is some way to describe that plane. In three-dimensions, we can simply use the surface normal of the plane. It may make more sense to you to think of this as the axis of rotation. In two- and three-dimensions, that will be fine. In higher numbers of dimensions, this will just confuse things. Let’s say our normal starts at the origin and goes through the point . To make things nice, let’s also assume it is of unit length: . We can represent our rotation as . Then, we can rotate our points by multiplying on the left by and on the right by : .

By way of an example, let us suppose we are going to rotate the point by an angle , parallel to the xy-plane. We will expect that our z-coordinate remains the same, but that the other two coordinates change. First, let us let and . The normal to the xy-plane is just the z-axis. So, our is going to be . This leaves us to multiply out (and it’s going to get messy):

Notice how the and the cancel out. Also, notice how . So, we can simplify to an extent like this:

If we go back to the double angle identites, we find that while . So, our final formula is:

### Denouement

I know that in the complex number case and in the Clifford algebra case, I used . In this case, I used (swapping the roles of and ). I could have used either in the complex number case since the complex numbers are commutative: for all complex numbers and . Thus, . I probably should have used for the complex case and still used for the Clifford algebra case.

There is a technical reason for the difference. This may sail right over your head if you haven’t done much hardcore linear algebra. But, when we are using the complex numbers or the quaternions to represent rotations, we are really jamming a linear form into a vector and pretending like they’re the same thing. We are glossing over the difference between a vector space and its dual space by just pretending they are the same. We can get away with that in the complex numbers and the quaternions, but we could not get away with it in the Clifford algebra case. This is because the three-dimensional bivectors make up the dual space of the vectors. So, when we’re using three-dimensional bivectors, we are explicitly using the dual space instead of taking advantage of the isomorphism between the dual space and the original vectors. When we get to four dimensions or more, the rotations aren’t even in the dual space.

For a more English, less Math, version of the above, look at it this way. Really, a rotation is something fundamentally different than a vector. We lucked out with the complex numbers and the quaternions in that we were still able to represent rotations with something like a vector (though in the quaternion case, it was a vector plus a scalar). The luck in the quaternion case isn’t perfect, it is off by a few signs here and there. In more dimensions, we won’t be so lucky. In three dimensions, there are three degrees of freedom for a rotation. In four dimensions, there are six degrees of freedom. We are never going to jam those six degrees of freedom into our puny four-dimensional vector.

### Next time

Next time, we will do these transformations of three-dimensional space using Clifford algebras instead of quaternions.

[…] using quaternions for rotating, translating, and scaling three-dimensional space. […]

The purpose of the angles is not for rotating but to identify the n roots of the complex number. These angles are only obtained by finding the arcotangent of the complex ratio. The example of costheta and sintheta which you mention works with theta equalling 90 degrees but this results in the same axes not a 90 degree rotation of the axes.

Further to my comments of 19 April 2012, 90 degrees rotation of the complex plane is fairly easy if the correct procedure is followed. If the point on the complex plane is say x=+5 and y=+2 then a 90 degree clockwise rotation can be achieved by making x=2 and y=-5. A further clockwise 90 degree rotation can be achieved by making y=-5 and x=-2 which is the negative of the first point on the complex plane and is the same result as 180 degree angle of the Cotes format of the complex numbers. However this similarity is not shared by smaller angle rotations. Curiously enough this 90 degree rotation can also be achieved on a three dimensional solid such as a sphere where we have three coordinates say x=+5 y=+2 and z=+9. We also have 8 quadrants. Each 90 degree rotation involves one change of sign and one change of position of the coordinates. It seems that this cannot be achieved by smaller angle rotations.

There is careless error in my comments of 29 April 2012. The third sentence should be A further clockwise 90 degree rotation can be achieved by making x=-5 and y=-2 which really is the negative of the first point on the complex plane, apologies.