Home > Research > Short Notes

Site map

3-D Rotations

Here are various notes on 3D rotations, including converting from axis-angle to vector and back.

Contents:

1. Rotating a Point About a Given Axis

To rotate a point p by an angle q about an axis a, where |a|=1,

p' = a . p a + (p - a . p a) cos q + a × p sin q
= p cos q + a . p a (1-cos q) + a × p sin q

2. Converting the Vector Form To a Matrix Form

To convert this to a matrix form, p'=M p, where M is a function of a and t, use these. The problem they solve is as follows. Suppose we want to rotate an object by 45° about the axis (1,2,3). We want some matrix M, which depends only on 45° and (1,2,3). Then we will rotate the object by multiplying its points by M. In fact, M would be this matrix:

0.07142857142 - 0.6589265829 0.7488081981
0.9446408685 0.2857142857 0.1613101866
- 0.3202367695 0.6958326704 0.6428571428

Now, instead of 45° and (1,2,3), think of a general angle, t, and axis, a.

We will work up to M in stages. First, is to find a matrix that depends only on a such that multiplying it by point p is the same as calculating a · p a. Here it is.

a12 a1a2 a1a2
a1a2 a22 a2a3
a1a3 a2a3 a32

This matrix has the following property:

a · p a =
a12 a1a2 a1a3
a1a2 a22 a2a3
a1a3 a2a3 a32
p1
p2
p3

Next, this matrix:

0 - a3 a2
a3 0 - a1
- a2 a1 0

has this useful property:

a × p =
0 - a3 a2
a3 0 - a1
- a2 a1 0
p1
p2
p3

With them, we can find a matrix M to turn equation

p' = p cos t + a · p a (1- cos t) + a × p sin t

into a matrix multiplication, p' = Mp, where

M =

It is complicated enough that you don't want to try memorizing it or copying it by hand. Even one widely-used text, Foley, got one sign wrong in one edition. My method:

  1. I originally created the matrix with my Maple rotmat routines, and wrote it in LaTeX format.

  2. I copied the formula from last year's handout, which I'd written in LaTeX, into a small LaTeX file.

  3. I tried to use latex2html to convert it, but that failed since it couldn't find any fonts.

  4. So, I ran LaTeX on it, and displayed the result with xdvi.

  5. Finally, I used xv to grab the xdvi window, crop it, and save it as a gif file.

  6. Moral: Math isn't easy on the web.

3. Telling If a Matrix is a Rotation Matrix

Since a rotation preserves distances, and therefore preserves angles, then, if ri is the i-th row, and ci is the i-th column, then

ri . rj = ci . cj = deltaij
Also,
det(M) = 1

Here is an explanation of these tests for whether a matrix, M, is a rotation.

  1. |M|=1 since the determinant is how much the volume of a small cube scales.

  2. The length of the first column, when treating that as a vector, is one, since that is the vector (1,0,0) after the transformation. Ditto the other columns.

  3. The columns are perpendicular to each other since the transformed axes must still be perpendicular.

4. Finding the Axis and Angle of a Rotation Matrix

  1. The eigenvalues are

    • 1,

    • cosq ± i sin q.

  2. If q = 180°, then the eigenvalues will be 1, -1, -1.

  3. The axis is the eigenvector corresponding to the eigenvalue of 1.

  4. You can get the angle, apart from some ambiguity, from the other eigenvalues.

  5. There is a complication because if you invert the axis and also negate the angle of rotation, you get the same rotation. This means that you can get two possible axis/angle combos from one matrix.

  6. Here is another way to find the axis, if q is not 0 ° or 180°. If M=mij is the matrix and a is the normalized axis, then

    2 a sinq= (m32-m23,m13-m31,m21-m12).

    Therefore,

    (m32-m23,m13-m31,m21-m12)

    is an unnormalized axis, and its length is 2 sinq.

  7. Here is another way to find the angle, up to an ambiguous sign. The trace of a matrix, which is the sum of the diagonal elements, is independent of the coordinate system used, so long as that is orthonormal. This implies that the trace is the sum of the eigenvalues. Here that is

    1+cos q + i sin q + cos q - sin q
    or
    1 + 2 cos q

    Therefore,

    q = arccos ( (m11+m22+m33-1)/2)

    Note that this gives 2 possibilities.

5. Noncommutativity

Generally two rotations do not commute; the order matters. Similarly 3-D matrices do not commute. Some rotations do commute:

  1. 2D rotations.

  2. 3D rotations about the same axis; that is really 2D.

  3. Infinitesimal rotations. Small rotations almost commute.

  4. If one rotation is 180°, then it sometimes commutes with other rotations.

6. Paper on Rotations

See my paper summarizing rotation methods, "Efficient Rotation of an Object", IEEE Transactions on Computing, Nov. 1983. It compares Euler angles, quaternions, and other methods. It shows how to optimize animation rotations using quaternions.

7. Other Relevant Pages

  1. Rotations in 4d and other dimensions.
  2. Maple example of 3D rotation.