We rotate an object around the axis of a coordinate system rotating together with the object. First we rotate it by $\phi$ angle around the $z$ axis, then by $\theta$ around the $y$ axis and finally by $\psi$ around the $z$ axis. The rotation matrix representing the position transformation for this operation is

Let $\mathbf{r}$ the position of an object. By the orthonormal basis, it can be represented as

$(1)$
**Rotation around the $z$ axis**:

We rotate the object by angle $\phi$ about the $z$ axis of $C$.
We rotate not only the object but also the coordinate system $C$ in the same way,
and define the rotated coordinate system as the new coordinate system $C'$.
($C'$ is the coordinate system obtained by rotating $C$ by angle $\phi$ about the $z$ axis of $C$.)
coordinate $C$ (dotted line) and $C'$ (orange line)

Let $x'$, $y'$, and $z'$ be the axes of $C'$
, and $\mathbf{e}_{x}'$, $\mathbf{e}_{y}'$, and $\mathbf{e}_{z}'$ be unit vectors whose direction is $x'$, $y'$, and $z'$ axis, respectively.
These form the orthonormal basis of $C'$.
Let $\mathbf{r}'$ be the position of the object after the rotation. Since the object and the coordinate system rotate in the same way, the relative position of $C'$ and $\mathbf{r}'$ after rotation is the same as that of $C$ and $\mathbf{r}$ before rotation (see the figure below).

Rotation of the coordinate and the position viewed from above of the $z$ axis.
The relative position of them is invariant under rotation.

Therefore,
the coordinate value of $\mathbf{r}'$ with respect to the basis of $C'$ is
the same as that of $\mathbf{r}$ with respect to the basis of $C$ (the above expression of $\mathbf{r}$).
That is,
$\mathbf{r}'$ can be represented as
$(2)$ ** Rotation around the $y'$ axis**:

Next, we rotate the object by angle $\theta$ about the $y'$ axis of $C'$.
We rotate not only the object but also the coordinate system $C'$ in the same way,
and define the rotated coordinate system as the new coordinate system $C''$.
($C''$ is the coordinate system obtained by rotating $C'$ by angle $\theta$ about the $y'$ axis of $C'$.)
Coordinate systems $C$, $C'$ (dotted line) and $C''$ (oragne line)

Let $x''$, $y''$, and $z''$ be the axes of $C''$
, and $\mathbf{e}_{x}''$, $\mathbf{e}_{y}''$, and $\mathbf{e}_{z}''$ be unit vectors whose direction is $x''$, $y''$, and $z''$ axis, respectively.
These form the orthonormal basis of $C''$.
Let $\mathbf{r}''$ be the position of the object after the rotation. Since the object and the coordinate system rotate in the same way, the relative position of $C''$ and $\mathbf{r}''$ after rotation is the same as that of $C'$ and $\mathbf{r}'$ before rotation (see the figure below).

Rotation of the coordinate and the position viewed from above of the $y'$ axis.
The relative position of them is invariant under rotation.

Therefore,
the coordinate value of $\mathbf{r}''$ with respect to the basis of $C''$ is
the same as that of $\mathbf{r}'$ with respect to the basis of $C'$ (the above expression of $\mathbf{r}'$).
That is,
$\mathbf{r}''$ can be represented as
$(3)$ **Rotation around the $z''$ axis**:

Finally, we rotate the object by angle $\psi$ about the $z''$ axis of $C''$.
We rotate not only the object but also the coordinate system $C''$ in the same way,
and define the rotated coordinate system as the new coordinate system $C'''$.
($C'''$ is the coordinate system obtained by rotating $C''$ by angle $\psi$ about the $z''$ axis of $C''$.)
Coordinate systems $C$, $C'$, $C''$ (dotted line) and $C'''$ (orange line)

Let $x'''$, $y'''$, and $z'''$ be the axes of $C'''$ , and $\mathbf{e}_{x}'''$, $\mathbf{e}_{y}'''$, and $\mathbf{e}_{z}'''$ be unit vectors whose direction is $x'''$, $y'''$, and $z'''$ axis, respectively. These form the orthonormal basis of $C'''$.

Let $\mathbf{r}'''$ be the position of the object after the rotation. Since the object and the coordinate system rotate in the same way, the relative position of $C'''$ and $\mathbf{r}'''$ after rotation is the same as that of $C''$ and $\mathbf{r}''$ before rotation (see the figure below).

Rotation of the coordinate and the position viewed from above of the $z''$ axis.
The relative position of them is invariant under rotation.

Therefore,
the coordinate value of $\mathbf{r}'''$ with respect to the basis of $C'''$ is
the same as that of $\mathbf{r}''$ with respect to the basis of $C''$ (the above expression of $\mathbf{r}''$).
That is,
$\mathbf{r}'''$ can be represented as
Let $r_{x}'''$, $r_{y}'''$, and $r_{z}'''$ be coordinates values of $\mathbf{r}'''$ represented by the basis $\{ \mathbf{e}_{x}, \mathbf{e}_{y}, \mathbf{e}_{z} \}$:

Here, $ r_{x}''',r_{y}''',r_{z}''' $ is the position of the object after the three rotations, and $ r_{x},r_{y},r_{z} $ is the initial position. Therefore, the above transformation formula shows that the position of the object after the three rotations is obtained by operationg the rotation matrix

The three angles $\phi,\theta,\psi$ are caled