November 22, 2024

Clear Graphical and Mathematical Explanation of Yaw, Pitch and Roll Euler Angles – Part 2

This is the second part of the tutorial on Euler angles and rigid kinematics. These tutorials are important for robotics and aerospace engineers. In this tutorial, we provide a clear explanation of Yaw, Pitch, and Roll Euler angles. We focus on the so-called 3-2-1 Yaw, Pitch, and Roll Euler angles. In the first part of this tutorial which can be found here, we focused on the classical Z-Z’-Z” Euler angles. The YouTube tutorial accompanying this post is given below.

Graphical Interpretation and Geometry of Yaw-Pitch-Roll Euler Angles and Rotations

The yaw-pitch-roll Euler angles are animated in the video shown below. Before continuing to read the rest of this tutorial, first, watch the video given below in order to better understand the geometry of yaw-pitch-roll Euler angles.

The yaw-pitch-roll angles and induced rotations are graphically explained in the figure below.

Figure 1: Yaw, pitch, and roll angles and induced rotations.

The coordinate system 0 with the coordinate axes X_{0}Y_{0}Z_{0} is an inertial (fixed) coordinate system.

We have three rotations

  1. Rotation around the Z_{0} axis for the angle of \theta_{1}. This is the yaw rotation. This rotation defines the coordinate system D with the coordinate axes X_{D}Y_{D}Z_{D}.
  2. Rotation around the Y_{D} axis for the angle of \theta_{2}. This is the pitch rotation. This rotation defines the coordinate system C with the coordinate axes X_{C}Y_{C}Z_{C}.
  3. Rotation around the X_{C} axis for the angle of \theta_{3}. This is the roll rotation. This rotation defines the coordinate system B with the coordinate axes X_{B}Y_{B}Z_{B}.

In robotics and aerospace engineering, coordinate systems are also called frames. The coordinate system B is also called the body frame. This is the frame that is rigidly attached to the body of the object and it rotates with the object. The directions of its axes are usually along the lines of symmetry or along the so-called principal axes or principal axes of inertia. We can also interpret the above rotations as follows. The body frame is rigidly attached to the body. After the yaw rotation, the body frame coincides with the frame D. After the pitch rotation, the body frame coincides with the coordinate system C. Finally, after the roll rotation, the coordinate system B is in its final position.

The angles \theta_{1}, \theta_{2}, and \theta_{3} are the yaw-pitch-roll Euler angles. The angle \theta_{1} is called the yaw angle. The angle \theta_{2} is the pitch angle. The angle \theta_{3} is the roll angle.

Next, let us introduce the following notation. Let \mathbf{r} be a vector. Then, the notation \mathbf{r}^{B} is the notation for the vector \mathbf{r} expressed in the coordinate system B with the following projections in the coordinate system B:

(1)   \begin{align*}\mathbf{r}^{B}=\begin{bmatrix} x_{B} \\ y_{B} \\ z_{B}   \end{bmatrix}\end{align*}

An equivalent notation is valid for \mathbf{r}^{C}, \mathbf{r}^{D}, and \mathbf{r}^{0}, that is

(2)   \begin{align*}\mathbf{r}^{C}=\begin{bmatrix} x_{C} \\ y_{C} \\ z_{C}   \end{bmatrix},\;\; \mathbf{r}^{D}=\begin{bmatrix} x_{D} \\ y_{D} \\ z_{D}   \end{bmatrix},\;\; \mathbf{r}^{0}=\begin{bmatrix} x_{0} \\ y_{0} \\ z_{0}   \end{bmatrix}\end{align*}

The figure below illustrates the vector \mathbf{r}^{B} in the coordinate system B.

Figure 2: Vector \mathbf{r}^{B} with the coordinate system B.

This vector has the following projections in the coordinate system B.

(3)   \begin{align*}\mathbf{r}^{B}=\begin{bmatrix} - \frac{1}{2}  \\  \frac{\sqrt{3}}{2} \\ 0   \end{bmatrix}\end{align*}

We consider the following important problem.


We are given the angles of rotation \theta_{1}, \theta_{2} and \theta_{3} and we are given the projections of the vector \mathbf{r} in the coordinate system B. That is, we are given \mathbf{r}^{B}. We want to determine the coordinates of the vector \mathbf{r} in the coordinate system 0, that is, we want to determine the projections of \mathbf{r}^{0}.

This problem is graphically illustrated in the figure below. We want to find the projections of the vector \mathbf{r}^{B} in the coordinate system 0.

Figure 3: Vector \mathbf{r}^{B} with the coordinate systems B and 0.

To solve this problem, we need to use rotation matrices that are explained in our previous tutorials, given here, here, and here. Let us now look at the rotation \theta_{3} shown in Fig. 1. By using the rotation matrices, we can represent the vector \mathbf{r}^{B} in the coordinate system C by using this transformation

(4)   \begin{align*}\mathbf{r}^{C}=R(\theta_{3}) \cdot \mathbf{r}^{B}=R^{C}_{B}\cdot \mathbf{r}^{B}\end{align*}

where R(\theta_{3})=R^{C}_{B} is the rotation matrix. The matrix R(\theta_{3}) is also denoted by R^{C}_{B}. The notation R^{C}_{B} is the classical notation for the rotation matrix that transforms the coordinate system B into the coordinate system C. Since the rotation is performed around the X_{C} axis, according to our previous tutorial on rotation matrices, which can be found here, the rotation matrix has the following form

(5)   \begin{align*}R(\theta_{3})=\begin{bmatrix} 1 & 0 & 0 \\ 0 & \cos(\theta_{3}) &  -\sin(\theta_{3}) \\ 0 & \sin(\theta_{3}) & \cos(\theta_{3})   \end{bmatrix}\end{align*}

Next, by using the same logic, from Fig. 1. above, we obtain

(6)   \begin{align*}\mathbf{r}^{D}=R(\theta_{2}) \cdot \mathbf{r}^{C} = R^{D}_{C} \cdot \mathbf{r}^{C}\end{align*}

where R(\theta_{2}) (or equivalently, R^{D}_{C}) is the rotation matrix transforming the coordinate system C into the coordinate system D. Since the rotation is performed with respect to the axis Y_{D}, according to our previous tutorial, which can be found here, the rotation matrix R(\theta_{2}) is defined by

(7)   \begin{align*}R(\theta_{2})=\begin{bmatrix}  \cos(\theta_{2}) & 0 & \sin(\theta_{2})\\ 0 & 1 & 0 \\ -\sin(\theta_{2}) & 0 & \cos(\theta_{2})   \end{bmatrix}\end{align*}

Finally, by using the same logic, from Fig. 1 above, we have

(8)   \begin{align*}\mathbf{r}^{0}=R(\theta_{1}) \cdot \mathbf{r}^{D}=R^{0}_{D}\cdot \mathbf{r}^{D}\end{align*}

where \mathbf{r}^{0} is the representation of the vector \mathbf{r}^{B} in the coordinate system XYZ, and R(\theta_{1}) (or equivalently, R^{0}_{D}) is the rotation matrix transforming the coordinate system D into the coordinate system 0. Since the rotation is performed with respect to the axis Z_{0}, according to our previous tutorial, which can be found here, the rotation matrix R(\theta_{1}) is defined by

(9)   \begin{align*}R(\theta_{1})=\begin{bmatrix} \cos(\theta_{1}) & -\sin(\theta_{1}) & 0 \\ \sin(\theta_{1}) & \cos(\theta_{1}) & 0 \\ 0 & 0 & 1\end{bmatrix} \end{align*}

By combining the equations (4), (6), and (8) we obtain

(10)   \begin{align*}\mathbf{r}^{0}=R(\theta_{1}) \cdot \mathbf{r}^{D}=R(\theta_{1}) R(\theta_{2}) \cdot \mathbf{r}^{C}= R(\theta_{1}) R(\theta_{2})R(\theta_{3}) \cdot \mathbf{r}^{B}\end{align*}

The last expression can be written compactly as follows

(11)   \begin{align*}\mathbf{r}^{0}=M(\theta_{1},\theta_{2},\theta_{3}) \mathbf{r}^{B}\end{align*}

where

(12)   \begin{align*}M(\theta_{1},\theta_{2},\theta_{3})=R(\theta_{1}) R(\theta_{2})R(\theta_{3})\end{align*}

The matrix M(\theta_{1},\theta_{2},\theta_{3}) is the direction cosine matrix. It transforms the projections of vectors from the coordinate system B to projections of vectors in the coordinate system 0. In our previous tutorial, which can be found here, we explained the main properties of the direction cosine matrix. Next, let us find the explicit form of the matrix M(\theta_{1},\theta_{2},\theta_{3}):

(13)   \begin{align*}& M(\theta_{1},\theta_{2},\theta_{3})=R(\theta_{1}) R(\theta_{2})R(\theta_{3})= \\& =  \begin{bmatrix}c\left(\theta_{1} \right) c\left(\theta_{2} \right) & - s\left(\theta_{1} \right) c\left(\theta_{3} \right) + s\left(\theta_{2} \right) s\left(\theta_{3} \right) c\left(\theta_{1} \right) & s\left(\theta_{1} \right) s\left(\theta_{3} \right) + s\left(\theta_{2} \right) c\left(\theta_{1} \right) c\left(\theta_{3} \right)\\ s\left(\theta_{1} \right) c\left(\theta_{2} \right) & s\left(\theta_{1} \right) s\left(\theta_{2} \right) s\left(\theta_{3} \right) + c\left(\theta_{1} \right) c\left(\theta_{3} \right) & s\left(\theta_{1} \right) s\left(\theta_{2} \right) c\left(\theta_{3} \right) - s\left(\theta_{3} \right) c\left(\theta_{1} \right) \\ -s\left(\theta_{2} \right) & s\left(\theta_{3} \right) c\left(\theta_{2} \right) & c\left(\theta_{2} \right) c\left(\theta_{3} \right)\end{bmatrix}\\\end{align*}

where c() is the short notation for \cos() and s() is the short notation for \sin().

The equation (11) solves our problem. The Python code given below is used to compute the direction cosine matrix M:


from sympy import * 
import numpy as np

init_printing()

theta1=symbols('theta1')
theta2=symbols('theta2')
theta3=symbols('theta3')


Rtheta1=Matrix([[cos(theta1) , -sin(theta1) , 0],
                [sin(theta1) , cos(theta1), 0],
                [0 , 0, 1]
                ])


Rtheta2=Matrix([ [cos(theta2),0, sin(theta2)],
                 [0, 1, 0],
                 [-sin(theta2), 0, cos(theta2)]
                 ])

Rtheta3=Matrix([ [1, 0, 0],
                 [0 ,cos(theta3),-sin(theta3)],
                 [0 ,sin(theta3)  , cos(theta3) ]
                 ])

# double check that inverses are transposes 
simplify(Rtheta1.T*Rtheta1)

simplify(Rtheta2.T*Rtheta2)

simplify(Rtheta3.T*Rtheta3)


# determine the direction cosine matrix
M=Rtheta1*Rtheta2*Rtheta3
# print(M)
# double check the orthogonality
simplify(M.T*M)
simplify(M.T*M -eye(3)) 


# generate the latex script
print_latex(M)