I'll start with 2D rotation and transformation matrices and extend this to 3D.
Physical rotation of a vector in 2D
Suppose you have a vector with cartesian coordinates (x,y) and want to rotate this by some angle theta. I'll use the conventional notations
- the x-axis is horizontal, positive to the right,
- the y-axis is vertical, positive upward,
- vectors are expressed as column vectors, and
- rotation is positive counterclockwise.
Expressed as a column vector, the vector from the origin to (x,y) is
\boldsymbol{r} = \bmatrix x\\y\endbmatrix
The coordinates of the endpoint of the rotated vector are (derivation is an exercise left to the reader) (x\cos\theta - y\sin\theta, x\sin\theta + y\cos\theta) or
\boldsymbol{r}' =<br />
\bmatrix x\cos\theta - y\sin\theta \\ x\sin\theta + y\cos\theta\endbmatrix<br />
= \bmatrix \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \endbmatrix \, \bmatrix x\\y\endbmatrix<br />
= \mathbf{R}(\theta) \, \boldsymbol{r}
where
\mathbf{R}(\theta)<br />
\equiv \bmatrix \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \endbmatrix<br />
is the 2D matrix that
physically rotates a column vector by an angle \theta.
Transformation of a vector in 2D
If you physically rotate the \hat{\boldsymbol x} and \hat{\boldsymbol x} unit vectors by some angle \theta you will get a new coordinate system with unit vectors \hat{\boldsymbol x}' and \hat{\boldsymbol x}':
\aligned<br />
\hat{\boldsymbol x}' &= \mathbf{R}(\theta)\,\hat{\boldsymbol x} \\<br />
\hat{\boldsymbol y}' &= \mathbf{R}(\theta)\,\hat{\boldsymbol y}<br />
\endaligned
Given some point with coordinates (x,y) in the original coordinate system, the coordinates of that point in the rotated coordinate system are (derivation once again left to the reader) (x',y') = (x\cos\theta + y\sin\theta, -x\sin\theta + y\cos\theta) or
\boldsymbol{r}' =<br />
\bmatrix x\cos\theta + y\sin\theta \\ -x\sin\theta + y\cos\theta\endbmatrix<br />
= \bmatrix \cos\theta & \sin\theta \\ -\sin\theta & \cos\theta \endbmatrix \, \bmatrix x\\y\endbmatrix<br />
= \mathbf{T}(\theta) \, \boldsymbol{r}
where
\mathbf{T}(\theta)<br />
\equiv \bmatrix \cos\theta & \sin\theta \\ -\sin\theta & \cos\theta \endbmatrix<br />
is the 2D matrix that
transforms a column vector to the frame physically rotated by an angle \theta with respect to the original frame.
In this simple 2D world, the transformation and rotation matrices are obviously related by \mathbf{T}(\theta) = \mathbf{R}(-\theta). A much better way to look at this is that the two are transposes of one another: \mathbf{T}(\theta) = \mathbf{R}^T(\theta). The reason this is a much better way to look at things is that this transpose relationship holds in higher dimensions. Rotation and translation are conjugate operations.
Sequence of transformations in N-space
Suppose you have three reference frames in some
N-space with a common origin but different orientations. I'll denote these as frames
A,
B, and
C. Denote \boldsymbol{r}_A, \boldsymbol{r}_B, and \boldsymbol{r}_C as the representations of some vector
r in these three frames. These representations are related by the transformation matrices from one frame to another:
\aligned<br />
\boldsymbol{r}_B &= \mathb{T}_{A \to B} \boldsymbol{r}_A \\<br />
\boldsymbol{r}_C &= \mathb{T}_{A \to C} \boldsymbol{r}_A \\<br />
&= \mathb{T}_{B \to C} \boldsymbol{r}_B<br />
\endaligned
Combining the above,
\aligned<br />
\boldsymbol{r}_C &= \mathb{T}_{A \to C} \boldsymbol{r}_A \\<br />
&= \mathb{T}_{B \to C} \boldsymbol{r}_B \\<br />
&= \mathb{T}_{B \to C} (\mathb{T}_{A \to B} \boldsymbol{r}_A) \\<br />
&= (\mathb{T}_{B \to C} \mathb{T}_{A \to B}) \boldsymbol{r}_A<br />
\endaligned
The final step uses the fact that matrix multiplication is transitive. Since the above must be true for any vector
r,
\mathb{T}_{A \to C} = \mathb{T}_{B \to C}\,\mathb{T}_{A \to B}
With an even more rotations chained in a sequence,
\mathbf{T}_{F_1 \to F_n} = \mathbf{T}_{F_{n-1} \to F_n},\cdots\,\mathbf{T}_{F_1 \to F_2}
This result makes no assumptions of the dimensionality of the space. Transformation matrices
for column vectors chain from right-to-left extends to all dimensions. Since rotation is the transpose of transformation, rotation matrices chain left-to-right.
The order of operations here is very important for any dimension higher than two. Two dimensional transformation (or rotation) matrices commute. For higher dimensions, multiplication of transformation (or rotation) matrices is not commutative.
Rotation/Transformation in 3-space
Rotation/transformation in 2-space is much easier to comprehend than in 3-space. Obviously, a rotation or transformation matrix for a vector in 3-space in 3-space is a 3x3 matrix. Constructing or making sense of a 2x2 rotation or transformation matrix is an easy task. One way to construct a 3x3 rotation or transformation matrix is to construct the rotation/transformation as a sequence of simpler rotations/transformations.
Euler's rotation theorem will help in this regard. Euler's rotation theorem says that any rotation in three space is a rotation can be expressed as a 2D rotation about some axis in 3-space. In particular, the transformation matrices corresponding to rotations about the
x,
y, and
z axes are
\aligned<br />
\mathbf{T}_x(\theta) &=<br />
\bmatrix 1&0&0 \\ 0&\cos\theta&\sin\theta \\ 0&-\sin\theta&\cos\theta \endbmatrix \\<br />
\mathbf{T}_y(\phi) &=<br />
\bmatrix -\sin\phi&0&\cos\phi \\ 0&1&0 \\ \cos\phi&0&\sin\phi \endbmatrix \\<br />
\mathbf{T}_z(\psi) &=<br />
\bmatrix \cos\psi&\sin\psi&0 \\ -\sin\psi&\cos\psi&0 \\ 0&0&1 \endbmatrix<br />
\endaligned
While Euler angles are evil, they do serve a very useful purpose in the construction of transformation matrices.
Sources of confusion
One obvious source of confusion is the distinction between rotation and transformation. I harp on this because they are distinct concepts and because failing to distinguish between these concepts is the source of a lot of errors. In this post, I have use \boldsymbol R to denote a rotation matrix and \boldsymbol T to denote a transformation matrix to avoid confusion.
Another source of confusion is whether vectors are expressed as column or row vectors. While column vectors are used more widely than are row vectors, this is just convention. If you instead use a row vector convention,
- You will have to post-multiply a vector by a rotation or transformation matrix to form a rotated or transformed vector.
- The rotation matrix for a row vector is the transpose of the rotation matrix for a column vector; the same is true for transformation matrices.
- Rotation matrices for row vectors chain right-to-left and transformation matrices for row vectors chain left-to-right.
Last words
My wife has the last word. She wants me to stop playing and do some silly house chores.