December 23, 2024

Clear Graphical and Mathematical Explanation of Euler Angles – Part 1


In this rigid body dynamics, GNC (guidance, navigation, and control), and physics tutorial, we provide a clear explanation of Euler angles. In this tutorial, we focus on the so-called Z-X’-Z” Euler angles, and in the second part of this tutorial, we will focus on the Yaw-Pitch-Roll Euler angles. The YouTube tutorial accompanying this post is given below.

Mechanism of Euler Angles

Before we start with explanations, we need to explain the main motivation for creating this tutorial. There are a large number of books on robotics, dynamics, and aerospace topics that cover Euler angles. However, in these books, Euler angles are not properly and clearly graphically explained. Equations are immediately introduced without providing students with the necessary graphical and intuitive understanding of Euler angles. Due to this, in this tutorial, we dedicate special attention to the graphical understanding of Euler angles.

Euler angles are used in many applications. Generally speaking, we use Euler angles to represent the orientation of a rigid body in space. In aerospace applications, orientation is also called attitude. What is the orientation of a rigid body? The orientation of the rigid body is a sequence of rotations with respect to some fixed or translating frame that is used to uniquely define the current rotational state (orientation) of the body. For example, let us assume that we have a body that can rotate with respect to its center of mass. Then, let us arbitrarily rotate this body. Its orientation is a set of mathematical parameters that uniquely describe the current state of rotation of the body with respect to the fixed or inertial frame.

There are several approaches for selecting parameters that describe the orientation of a rigid body. One of the approaches is to use the Euler angles. Euler angles are three angles that are used to sequentially rotate three axes of a rigid body. By using Euler angles we can mathematically describe any rotational state or orientation of a rigid body. That is, Euler angles are used to mathematically represent, or better to say, define the orientation of a rigid body with respect to some coordinate system that is used as the reference.

In addition to three Euler angles, we need additional three parameters to completely define the position and orientation of a rigid body in space. The position of a rigid body in the space is described by three parameters. They are X, Y, and Z coordinates of the center of the mass of the body.

In the sequel, we thoroughly explain the concept of Euler angles. However, we suggest that you first watch the following video tutorial that graphically explains three Euler angles and three sequential rotations produced by Euler angles.

Next, we thoroughly explain the Euler angles and induced rotations. The graph given below explains the Euler angle convention.

Figure 1: Sequence of Euler rotations.

This figure shows a 3D cube that is sequentially rotated 3 times. The initial coordinate system XYZ is centered at the center of the mass of the cube. The Euler angle rotations are described as follows:

  1. In the first rotation, we rotate the cube around the Z axis. The rotation angle is \theta_{1}. This rotation defines a new coordinate system X'Y'Z'.
  2. Then, we rotate the cube around the X' axis. The angle or rotation is \theta_{2}. This rotation defines a new coordinate system X''Y''Z''.
  3. Finally, we rotate the cube around Z'' axis. The angle or rotation is \theta_{3}. This rotation defines the final coordinate system X'''Y'''Z'''. We performed three sequential rotations.

The angles \theta_{1}, \theta_{2} and \theta_{3} are called the Z,X’,Z” Euler angles. They are also called 3-1-3 Euler angles. The notation Z,X',Z'' or 3-1-3 denotes the sequential axes of rotation. There are also other ways for defining the Euler angles by using other axes of rotation. However, more about this in our future tutorials.

Let us introduce the following notation for the coordinate systems in order to simplify the mathematical notation in the sequel:

  • The coordinate system XYZ is denoted by 0.
  • The coordinate system X'Y'Z' is denoted by D.
  • The coordinate system X''Y''Z'' is denoted by C.
  • The coordinate system X'''Y'''Z''' is denoted by B.

The Euler angles with the new notation for coordinate systems are shown in the figure below.

Figure 2: Euler angles with the new notation for coordinate systems.

Here, we should mention the following. The coordinate system B is the so-called body coordinate system and its direction is always in the direction of the principal axes of the body (axes of symmetry in our case). This coordinate system is rigidly attached to the body. In the initial configuration, this coordinate system coincides with the coordinate system 0. Then, after the first rotation, this coordinate system coincides with D. Then, after the second rotation, this coordinate system coincides with C.

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*}

For example, let us assume that the 3D cube is a unit cube. Then, a vertex or a corner of the cube in the coordinate system B has the following projections

(2)   \begin{align*}\mathbf{r}^{B}=\begin{bmatrix} 0.5  \\ 0.5 \\ 0.5   \end{bmatrix}\end{align*}

The point determined by this vector is shown in the figure below.

Figure 3: Point and the corresponding vector in the body frame of the unit cube at the location (0.5,0.5,0.5)

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

(3)   \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*}

We want to address the following 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}.

Let us illustrate this problem with an example. Consider the figure shown below.

Figure 4: Figure illustrating the coordinate transformation problem. We are given the vector \mathbf{r}^{B} with the coordinates expressed in the coordinate system B. Our goal is to express the coordinates of this vector in the coordinate system 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. 2.. 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 Z_{c} axis, according to our previous tutorial on the rotation matrices which can be found here, the rotation matrix has the following form

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

Next, by using the same logic, from Fig. 2. 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 X_{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}  1 & 0 & 0 \\ 0 & \cos(\theta_{2}) &  -\sin(\theta_{2})  \\ 0 & \sin(\theta_{2}) & \cos(\theta_{2}) \end{bmatrix}\end{align*}

Finally, by using the same logic, from Fig. 2 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, 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}- s{\left(\theta_{1} \right)} s{\left(\theta_{3} \right)} c{\left(\theta_{2} \right)} + c{\left(\theta_{1} \right)} c{\left(\theta_{3} \right)} & - s{\left(\theta_{1} \right)} c{\left(\theta_{2} \right)} c{\left(\theta_{3} \right)} - s{\left(\theta_{3} \right)} c{\left(\theta_{1} \right)} & s{\left(\theta_{1} \right)} s{\left(\theta_{2} \right)}\\  s{\left(\theta_{1} \right)} c{\left(\theta_{3} \right)} + s{\left(\theta_{3} \right)} c{\left(\theta_{1} \right)} c{\left(\theta_{2} \right)} & - s{\left(\theta_{1} \right)} s{\left(\theta_{3} \right)} + c{\left(\theta_{1} \right)} c{\left(\theta_{2} \right)} c{\left(\theta_{3} \right)} & - s{\left(\theta_{2} \right)} c{\left(\theta_{1} \right)}\\ s{\left(\theta_{2} \right)} s{\left(\theta_{3} \right)} & s{\left(\theta_{2} \right)} c{\left(\theta_{3} \right)} & c{\left(\theta_{2} \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:

# -*- coding: utf-8 -*-
"""
Demonstration of rotation matrices and
direction cosine matrix in Python 
by using the SymPy library 
- Symbolic Python Toolbox 
Author: Aleksandar Haber
"""

from sympy import * 

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([[1, 0, 0],
                 [0, cos(theta2), -sin(theta2)],
                 [0, sin(theta2), cos(theta2)]
                 ])

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

# 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)