After having seen how to calculate the rotation matrix given the Euler angles, today we will see the opposite operation, again with the aim of developing a cross platform solution in C# to calculate the Euler angles from a rotation matrix.

## Rotation Matrix to Euler Angles

The code to be considered takes into account 3 input parameters:

- the
**rotation matrix**, expressed as a multidimensional array of doubles; - the
**rotation sequence of the axes**with which we wish to carry out the transformation; - the
**units of the Euler angles**we wish to calculate.

Also in this version of the code, we use **two enums** to better organise the code, from line 1 to 5 to define the two **types of angles supported** (*radians* and *degrees*), from 7 to 12 for the **various axis rotation sequences** (*ZYX*, *ZYZ*, *XYZ*).

To finish, we do a simple test, starting with calculating the rotation matrix defined as [33, 67, 32], where each value describes the rotations with respect to the X, Y and Z axes respectively.

At this point, we conclude the development by calculating backwards (row 17) and printing the resulting Euler angles which are equal to the starting angles.

If we run the program we have just written, we will see that the final result, as long as we use rotations of type XYZ and ZYZ, will be a vector of doubles containing the values [33, 67, 32].

## Conclusions

As already seen in the previous article, the *rotation matrix* is a matrix operator that allows a vector to be rotated around a given axis in space. It is a very useful tool in various fields of application, such as in robotics when solving inverse kinematics problems or in reference system transformations.

In this article, we have therefore presented a solution in C# that allows the Euler angles to be obtained from a known rotation matrix.

## Leave A Comment