# Equivalent rotations of a set of rotations.

**URL:** https://discourse.vtk.org/t/equivalent-rotations-of-a-set-of-rotations/8355
**Category:** Support
**Created:** [April 22, 2022, 9:03pm UTC](https://discourse.vtk.org/t/equivalent-rotations-of-a-set-of-rotations/8355 "2022-04-22T21:03:12Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Luis\_Carlos\_Carneiro](https://discourse.vtk.org/user_avatar/discourse.vtk.org/luis_carlos_carneiro/32/1360_2.png) [@Luis\_Carlos\_Carneiro](https://discourse.vtk.org/u/Luis_Carlos_Carneiro)
#### Post date: [April 22, 2022, 9:03pm UTC](https://discourse.vtk.org/t/equivalent-rotations-of-a-set-of-rotations/8355/1 "2022-04-22T21:03:13Z")

</div>

Dear All,

Are there some site that I can convert the following set of rotations, of a 3D picture, i.e.

Rot Axe Y → Rot Axe X → Rot Axe Z → Rot Axe X → Rot Axe Y (or any other set of rotations)

in

Rot Axe X → Rot Axe Y → Rot Axe Z (in any sequence)

I have the intuition that can be done through matrices manipulation. But perhaps there are available some site that can input the angles and get the output angles. Or some script already done. Or some Matlab instruction. In last case you can give me the theoretical concerning that.

Thanks,

Luís Gonçalves

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [April 22, 2022, 9:43pm UTC](https://discourse.vtk.org/t/equivalent-rotations-of-a-set-of-rotations/8355/2 "2022-04-22T21:43:19Z")

</div>

You can go to `wolfram.com` and seach for EulerAngles, RawPitchYawAngles, etc.

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [April 28, 2022, 12:38pm UTC](https://discourse.vtk.org/t/equivalent-rotations-of-a-set-of-rotations/8355/3 "2022-04-28T12:38:42Z")

</div>

Hello,

You can multiply all your input rotations in their order to obtain a singe matrix called `R` and then do this:

```cpp
#include <cmath>

double yaw = std::atan2(R(1,0), R(0,0));
double pitch = std::atan2(-R(2,0), std::sqrt( R(2,1)*R(2,1) + R(2,2)*R(2,2))));
double roll = std::atan2(R(2,1), R(2,2));

```

Notice that we named the angles `yaw`, `pitch` and `roll` since whether they actually correspond to rotY, rotX and rotZ depends on your axes conventions (e.g. X is the first axis, right- or left handed, etc.).

Source: [Determining yaw, pitch, and roll from a rotation matrix](http://planning.cs.uiuc.edu/node103.html)

However, the solution above can exhibit numerical instability whereas the header-olny library Eigen’s implementation ([Eigen: Main Page](https://eigen.tuxfamily.org/dox/)) is gimbal-lock-proof:

```cpp
   #include <Eigen/Geometry>

   (...)

   Matrix3f R = ...; //multiply all your input rotations here.

   Vector3f angles = R.eulerAngles(2, 1, 0).reverse();

```

Refer to the documentation of `eulerAngeles()` here: [Eigen: Geometry module](https://eigen.tuxfamily.org/dox/group __Geometry__ Module.html#title20)

take care,

Paulo
