Here are various notes on 3D rotations, including converting from axis-angle to vector and back.
(This page requires you to enable Javascript and use a reasonable processor since the equations are rendered locally.)
Contents (hide)
- 1. The Purpose of this Page
- 2. Rotating a Point About a Given Axis
- 3. Example
- 4. Example 2
- 5. Converting the Vector Form To a Matrix Form
- 6. Examples
- 7. Telling If a Matrix is a Rotation Matrix
- 8. Examples
- 9. Finding the Axis and Angle of a Rotation Matrix
- 10. Paper on Rotation Methods
- 11. Other Relevant Pages
- 12. Other 3D Rotation Methods
- 13. Degrees of Freedom and Number of Coefficients
1. The Purpose of this Page
- There are several different ways to look at rotations. A general rule is, that when there several ways of doing something, then none of the ways is enormously better than the others. Otherwise, we'd never talk about the poorer methods.
- Rotation with an axis an angle is easy to understand.
- Rotation by a matrix is easy to combine with other rotations and other transformations.
- Rotation with quaternions is easy to animate, and also easy to combine several rotations, and is less sensitive to roundoff errors.
- Rotation with Euler angles is liked by mechanical engineers, perhaps because gimbal rings work like that.
- You can convert back and forth between methods.
2. Rotating a Point About a Given Axis
To rotate a point p by an angle \theta about an axis a, where |a|=1:
That was derived as follows:
- Decompose p into p_\|= (a\cdot p) \, a, a component parallel to a, and p_\bot = p - p_\|, a component perpendicular to a.
- p_\| doesn't change when rotated: p_\|' = p_\|
- p_\bot rotates in a plane perpendicular to a. p_\bot is like the x-axis, a is like the y-axis, and a\times p_\bot = a\times p is like the z-axis.
- p_\bot' = p_\bot \cos\theta + a\times p \sin\theta
- p'=p_\|'+p_\bot'
3. Example
Suppose that we want to rotate the point p=(3,2,1) by 45^\circ about the axis a=(1,0,0). Note that the length of a is 1, but the length of p can be anything.
a\cdot p = 3, so p_\|= a\cdot p \, a = 3a = (3,0,0).
p_\bot = p - p_\| = (3,2,1) - (3,0,0) = (0,2,1)
p_\|' = p_\| = (3,0,0)
(0,2,1) rotates in a plane perpendicular to a, a plane defined by (0,2,1) and (1,0,0)\times(0,2,1)=(0,-1,2)
p_\bot' = \cos\theta (0,2,1) + \sin\theta (0,-1,2) = (0,1.4,.7) + (0,-.7,1.4) = (0,.7,2.1)
p' = (3,0,0) + (0,.7,2.1) = (3,.7,2.1). Note that its length is the same as for p.
4. Example 2
Suppose we want to rotate the point p=(1,0,0) about the axis a=(1,1,1) by the angle 120^\circ.
- Since |a|=\sqrt{3} , we need to normalize it to \hat{a}=\left(\frac{1}{\sqrt{3}},\frac{1}{\sqrt{3}},\frac{1}{\sqrt{3}}\right).
- The component of p parallel to \hat{a} is p_\|=(p\cdot\hat{a}) \hat{a}=\frac{1}{\sqrt{3}}\left(\frac{1}{\sqrt{3}},\frac{1}{\sqrt{3}},\frac{1}{\sqrt{3}}\right)=\left(\frac{1}{3},\frac{1}{3},\frac{1}{3}\right).
- It doesn't change when rotated.
- The component of p perpendicular to \hat{a} is the rest of p, i.e., p_\bot=(1,0,0)-\left(\frac{1}{3},\frac{1}{3},\frac{1}{3}\right)=\left(\frac{2}{3},-\frac{1}{3},-\frac{1}{3}\right)
- p_\bot rotates in a plane perpendicular to a, where p_\bot acts as the x-axis and the y-axis is played by \hat{a}\times p_\bot= \left(0,\frac{1}{\sqrt{3}},-\frac{1}{\sqrt{3}}\right)
- Note that \cos120^\circ= -\frac{1}{2} and \sin120^\circ=\frac{\sqrt{3}}{2}
- p_\bot'=-\frac{1}{2}\left(\frac{2}{3},-\frac{1}{3},-\frac{1}{3}\right)+\frac{\sqrt{3}}{2}\left(0,\frac{1}{\sqrt{3}},-\frac{1}{\sqrt{3}}\right) =\left(-\frac{1}{3},\frac{2}{3},-\frac{1}{3}\right)
- p'=\left(\frac{1}{3},\frac{1}{3},\frac{1}{3}\right)+\left(-\frac{1}{3},\frac{2}{3},-\frac{1}{3}\right)=(0,1,0)
- That makes sense. Rotating a point on the x-axis by 120^\circ about (1,1,1) gives a point on the y-axis.
5. Converting the Vector Form To a Matrix Form
The problem is that the formula \color{blue}{p}' = (\color{red}{a} \cdot \color{blue}{p})\, \color{red}{a} + (\color{blue}{p} - (\color{red}{a} \cdot \color{blue}{p})\, \color{red}{a})\color{red}{\cos \theta}+ \color{red}{a} \times \color{blue}{p}\, \color{red}{\sin \theta} mixes up the rotation definition ( \color{red}{a} and \color{red}{\theta}) and the object ( \color{blue}{p} ) throughout the formula. We want to separate the formula into a part depending on the rotation and another part depending on the object, which interact simply:
\color{red}{M_{a,\theta}} means that \color{red}{M} is a matrix that depends only on \color{red}{a,\theta} .
To convert this to a matrix form, p'=M p, where M is a function of a and \theta, use these. The problem they solve is as follows. Suppose we want to rotate an object by 45^\circ about the axis (1,2,3). We want some matrix M, which depends only on 45^\circ and (1,2,3). Then we will rotate the object by multiplying its points by M. In fact, M would be this matrix:
Now, instead of 45^\circ and (1,2,3), think of a general angle, \theta, 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\cdot p\, a. Here it is.
This matrix has the following property:
Next, this matrix:
has this useful property:
With them, we can find a matrix M to turn equation
into a matrix multiplication, p' = Mp, where
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. I created the matrix with my Maple rotmat routines, and wrote it in LaTeX format.
6. Examples
- If a=(1,2,3) then write (a\cdot p)\, a as a matrix depending on
a times p. \color{blue}{(a\cdot p)\, a = \begin{pmatrix} 1&2&3\\2&4&6\\3&6&9\end{pmatrix} p}
- Write a\times p ditto. \color{blue}{a\times p = \begin{pmatrix}0&-3&2\\3&0&-1\\-2&1&0\end{pmatrix}p}
7. Telling If a Matrix is a Rotation Matrix
Since a rotation preserves distances, and therefore preserves angles, then, if r_i is the i-th row, and c_i is the i-th column, then
\delta_{ij} is defined as 1 if i=j and 0 otherwise.
Finally,
Here is an explanation of these tests for whether a matrix, M, is a rotation.
- \det(M)=1 since the determinant is how much the volume of a small cube scales.
- 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.
- The columns are perpendicular to each other since the transformed axes must still be perpendicular.
8. Examples
- The following matrix \begin{pmatrix} 1&1&0\\0&1&0\\0&1&1\end{pmatrix}is not a rotation matrix because the 2nd column has length \sqrt{2}\ne1.
- The following matrix \begin{pmatrix} 1&.6&0\\0&.8&0\\0&1&1\end{pmatrix}is not a rotation matrix because the first 2 columns are not perpendicular.
- The following matrix \begin{pmatrix} 1&0&0\\0&1&0\\0&0&-1\end{pmatrix}is not a rotation matrix because its determinant is -1.
9. Finding the Axis and Angle of a Rotation Matrix
- The eigenvalues are
\color{red}{1} \,\text{and}\, \color{red}{\cos\theta\pm i \sin \theta}
- If \theta = 180^\circ, then the eigenvalues will be 1, -1, -1.
- The axis is the eigenvector corresponding to the eigenvalue of 1.
- You can get the angle, apart from some ambiguity, from the other eigenvalues.
- 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.
- Here is another way to find the axis, if \theta is not
0^\circ or 180^\circ. If M=m_{ij} is the matrix
and a is the normalized axis, then 2 a \sin\theta = (m_{32}-m_{23}, m_{13}-m_{31},m_{21}-m_{12})Therefore,\color{red}{ (m_{32}-m_{23}, m_{13}-m_{31},m_{21}-m_{12}) }is an unnormalized axis, and its length is \color{red}{2\sin\theta} .
- Here is another way to find the angle, up to an ambiguous
sign. The trace of a matrix, which Research/Rotation3Dis 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 \theta + i \sin \theta + \cos \theta - \sin \theta = 1 + 2 \cos \theta
Therefore, \color{red}{\theta = \arccos \left({\frac{m_{11}+m_{22}+m_{33}-1}{2}}\right)}Note that this gives 2 possibilities.
10. Paper on Rotation Methods
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.
11. Other Relevant Pages
12. Other 3D Rotation Methods
- Quaternions
- Euler angles - very bad for animation, suffers gimbal lock
13. Degrees of Freedom and Number of Coefficients
- A 3D rotation has 3 degrees of freedom.
- Representing a rotation with Euler angles uses 3 coefficients, but Euler angles have problems.
- Matrices use 9 coefficients. When you multiply rotation matrices, roundoff error means that the result is not exactly a rotation. Projecting the matrix to the closest rotation matrix is a little messy.
- Quaternions use 4 coefficients, which is the sweet spot for number of coefficients. Fewer coefficients means less chance for trouble. Projecting a non-rotation quaternion to a close rotation quaternion is easy.
<< | Research Page List | >>