Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

3D Rotations and Transformations

3D Rotations

3D Rotations are fundamental transformations in space.

2D Rotation around Z-axis

The rotation of a point (x,y)(x, y) in the XYXY-plane (around the ZZ-axis) by an angle ϕ\phi (or θ\theta) is given by:

[xyz]=[cosϕsinϕ0sinϕcosϕ0001][xyz]\begin{bmatrix} x'\\ y'\\ z' \end{bmatrix} = \begin{bmatrix} \cos\phi & -\sin\phi & 0\\ \sin\phi & \cos\phi & 0\\ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x\\ y\\ z \end{bmatrix}

3D Axis-Aligned Rotation Matrices

Rotation around X-axis (Rx(θx)R_x(\theta_x))

[xyz]=[1000cosθxsinθx0sinθxcosθx][xyz]\begin{bmatrix} x'\\ y'\\ z' \end{bmatrix} = \begin{bmatrix} 1 & 0 & 0\\ 0 & \cos\theta_x & -\sin\theta_x\\ 0 & \sin\theta_x & \cos\theta_x \end{bmatrix} \begin{bmatrix} x\\ y\\ z \end{bmatrix}

Rotation around Y-axis (Ry(θy)R_y(\theta_y))

[xyz]=[cosθy0sinθy010sinθy0cosθy][xyz]\begin{bmatrix} x'\\ y'\\ z' \end{bmatrix} = \begin{bmatrix} \cos\theta_y & 0 & \sin\theta_y\\ 0 & 1 & 0\\ -\sin\theta_y & 0 & \cos\theta_y \end{bmatrix} \begin{bmatrix} x\\ y\\ z \end{bmatrix}

Right-Hand Coordinate Frame

The rotations typically follow the Right-hand coordinate frame convention

To determine the positive direction of rotation, curl your fingers from the first axis to the second; your thumb points in the direction of the third axis (the rotation axis).

  • XYX \rightarrow Y: positive rotation is around ZZ

  • YZY \rightarrow Z: positive rotation is around XX

Euler Angles and Decomposition

All 3D rotations can be decomposed into 3 axis-aligned rotations

These three angles of rotation are called Euler angles.

A common set of Euler angles is Roll-Pitch-Yaw (RPY):

  • θx=roll\theta_x = \text{roll}

  • θy=pitch\theta_y = \text{pitch}

  • θz=yaw\theta_z = \text{yaw}

The total rotation RR is a product of the individual rotations. For the Roll-Pitch-Yaw sequence (XYZX-Y-Z):

R=Rx(θz)Ry(θy)Rz(θz)R = R_x(\theta_z) R_y(\theta_y) R_z(\theta_z)

Important: The Application of Rotation matrices is from right to left

Combination of Euler Angles

There are 12 possible combinations of Euler angles (rotations).

This arises from two key choices when chaining rotations:

  1. Axis Permutations: There are 3!=63! = 6 possibilities for the order of axes (e.g., XYZ,YZX,ZYZX-Y-Z, Y-Z-X, Z-Y-Z).

  2. Tait-Bryant Angles: You only use two axis but three rotations (e.g., XYX,XZXX-Y-X, X-Z-X).

Composition of Rotations / Transformations

Rotation Composition

The rotation from frame CC to frame WW via an intermediate frame SS is a matrix product:

wRc=wRssRc\mathbf{^wR_c} = \mathbf{^wR_s} \mathbf{^sR_c}

The composition of two rotation matrices, R1R2R_1 R_2, is also orthonormal with a determinant of 1.

det(R1R2)=det(R1)det(R2)=11=1\det(R_1 R_2) = \det(R_1) \det(R_2) = 1 \cdot 1 = 1

The inverse of a composed rotation is: (R1R2)1=R21R11=R2TR1T(R_1 R_2)^{-1} = R_2^{-1} R_1^{-1} = R_2^T R_1^T

Homogeneous Transformation Composition

For homogeneous transformations T\mathbf{T} (which include both rotation and translation):

wTc=wTssTc\mathbf{^wT_c} = \mathbf{^wT_s} \mathbf{^sT_c}

3D Rotation Representations and DOF

All rotation representations must account for 3 Degrees of Freedom (DOF).

RepresentationDescriptionInitial free variables (Numbers)ConstraintsFinal DOF
Rotation Matrix R\mathbf{R}3×33 \times 3 matrix9 DOFdet(R)=1\det(R)=1, RTR=IR^T R = I3 DOF
Euler Angles(θx,θy,θz)(\theta_x, \theta_y, \theta_z)3 DOFNone3 DOF
Quaternions q\mathbf{q}(x,y,z,w)(x, y, z, w)4 DOFq=1|\mathbf{q}| = 1 (One constraint)3 DOF
Axis-Angle(u^,θu)(\mathbf{\hat{u}}, \theta_u)4 DOFu^=1|\mathbf{\hat{u}}| = 1 (Unit vector constraint)3 DOF

Roll-Pitch-Yaw to Rotation Matrix Conversion

For the Roll-Pitch-Yaw (RPY) sequence R=Rx(θx)Ry(θy)Rz(θz)R = R_x(\theta_x) R_y(\theta_y) R_z(\theta_z) , the individual rotation matrices are multiplied:

R=[cθzsθz0sθzcθz0001][cθy0sθy010sθy0cθy][1000cθxsθx0sθxcθx]R = \begin{bmatrix} c\theta_z & -s\theta_z & 0 \\ s\theta_z & c\theta_z & 0 \\ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} c\theta_y & 0 & s\theta_y \\ 0 & 1 & 0 \\ -s\theta_y & 0 & c\theta_y \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 \\ 0 & c\theta_x & -s\theta_x \\ 0 & s\theta_x & c\theta_x \end{bmatrix}

This product yields the final 3×33 \times 3 rotation matrix:

R=[r11r12r13r21r22r23r31r32r33]R = \begin{bmatrix} r_{11} & r_{12} & r_{13} \\ r_{21} & r_{22} & r_{23} \\ r_{31} & r_{32} & r_{33} \end{bmatrix}

Where cθ=cosθc\theta = \cos\theta and sθ=sinθs\theta = \sin\theta.

Rotation Matrix to Roll-Pitch-Yaw Conversion

Given a rotation matrix RR, the Euler angles (θx,θy,θz)(\theta_x, \theta_y, \theta_z) (Roll, Pitch, Yaw) can be extracted:

  1. Pitch (θy\mathbf{\theta_y}): The pitch angle can be calculated from the r31r_{31} element.

    sin(θy)=r31- \sin(\theta_y) = r_{31}

    θy=sin1(r31)[π2,π2]\theta_y = \sin^{-1}(-r_{31}) \in [-\frac{\pi}{2}, \frac{\pi}{2}]
  2. Roll (θx\mathbf{\theta_x}): The roll angle can be calculated using the arctan2\arctan2 function for quadrant-aware calculation:

    θx=arctan2(r32,r33)(π,π]\theta_x = \arctan2(r_{32}, r_{33}) \in (-\pi, \pi]
  3. Yaw (θz\mathbf{\theta_z}): The yaw angle can be similarly calculated using arctan2\arctan2.

    θz=arctan2(r21,r11)\theta_z = \arctan2(r_{21}, r_{11})

Gimbal Lock

Gimbal Lock is a significant problem encountered when using Euler angles.

It occurs when the pitch angle is θy=90=π2\theta_y = 90^{\circ} = \frac{\pi}{2}.

  • At this angle, cos(θy)=0\cos(\theta_y) = 0.

  • The first and third rotation axes (Roll and Yaw axes) become aligned (swapped).

  • This causes a loss of one Degree of Freedom (DOF), meaning two of the three rotation angles are redundant or indistinguishable.

Axis-Angle Representation (Rodrigues’ Formula)

The Axis-angle representation defines a rotation by a unit vector k^=[kx,ky,kz]T\mathbf{\hat{k}} = [k_x, k_y, k_z]^T and a rotation angle θ\theta.

  • The axis must be a unit vector: k^=kx2+ky2+kz2=1||\mathbf{\hat{k}}|| = \sqrt{k_x^2+k_y^2+k_z^2}=1.

The Rodrigues’ Formula converts this representation into the rotation matrix RR:

R=I+sinθ[k^×]+(1cosθ)[k^×]2R = I + \sin\theta [\mathbf{\hat{k}}_\times] + (1-\cos\theta) [\mathbf{\hat{k}}_\times]^2

Cross Product Matrix

The [k^×][\mathbf{\hat{k}}_\times] notation represents the Cross product matrix:

[k×]=[0kzkykz0kxkykx0][\mathbf{k}_\times] = \begin{bmatrix} 0 & -k_z & k_y\\ k_z & 0 & -k_x\\ -k_y & k_x & 0 \end{bmatrix}

The cross product of two vectors, a×b\mathbf{a} \times \mathbf{b}, can be computed as a matrix multiplication using the cross-product matrix of a\mathbf{a}:

a×b=[a×]b\mathbf{a} \times \mathbf{b} = [\mathbf{a}_\times]\mathbf{b}

The matrix A=[a×]A = [\mathbf{a}_\times] is a Skew-symmetric matrix, meaning AT=AA^T = -A.

Applying the Axis-Angle Rotation to a Point

Applying the rotation RR to a point p\mathbf{p} is:

Rp=p+sinθ(k^×p)+(1cosθ)k^×(k^×p)R\mathbf{p} = \mathbf{p} + \sin\theta(\mathbf{\hat{k}}\times\mathbf{p}) + (1-\cos\theta)\mathbf{\hat{k}}\times(\mathbf{\hat{k}}\times\mathbf{p})