Equivalent rotations of a set of rotations.

Hello,

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

#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

However, the solution above can exhibit numerical instability whereas the header-olny library Eigen’s implementation (Eigen: Main Page) is gimbal-lock-proof:

   #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

take care,

Paulo