# 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:** 1
**Showing post:** 3

<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

---

_[View the full topic](https://discourse.vtk.org/t/equivalent-rotations-of-a-set-of-rotations/8355)._
