Roll pitch and yaw from Rotation matrix with Eigen Library
Asked Answered
C

2

11

I need to extract the roll pitch yaw angles from a rotation matrix and I want to be sure that what I do is correct.

    Eigen::Matrix< simFloat, 3, 1> rpy = orientation.toRotationMatrix().eulerAngles(0,1,2);
    const double r = ((double)rpy(0));
    const double p = ((double)rpy(1));
    const double y = ((double)rpy(2));

Is that correct? Because I was reading here: http://eigen.tuxfamily.org/dox/group__Geometry__Module.html#gad118fececd448d7485ffea4858775e5a

And I was a bit confused when it says, at the end of the description, in which intervals are defined the angles.

Coen answered 16/12, 2014 at 15:38 Comment(0)
O
19

I think this is what you are looking for. Depending on how we use m.eulerAngles(0, 1, 2); Here's the code which get rotx, roty, rotz that is reconstructed with rotx*roty*rotz

Matrix3f m;

m = AngleAxisf(0.25*M_PI, Vector3f::UnitX())
  * AngleAxisf(0.5*M_PI, Vector3f::UnitY())
  * AngleAxisf(0.33*M_PI, Vector3f::UnitZ());

cout << "original rotation:" << endl;
cout << m << endl << endl;

Vector3f ea = m.eulerAngles(0, 1, 2); 
cout << "to Euler angles:" << endl;
cout << ea << endl << endl;

Matrix3f n;
n = AngleAxisf(ea[0], Vector3f::UnitX())
  * AngleAxisf(ea[1], Vector3f::UnitY())
  * AngleAxisf(ea[2], Vector3f::UnitZ()); 

cout << "recalc original rotation:" << endl;
cout << n << endl;

Thank you for your reference! I also firstly use Eigen. It's simply save a lot of work!

Objectionable answered 10/1, 2015 at 18:59 Comment(0)
N
6

The answer by Shawn Le is correct but I think the line should be

Vector3f ea = m.eulerAngles(2, 1, 0);

Then ea will hold the yaw pitch and roll value in that order. ZYX euler angle rotation is equivalent to XYZ fixed axis rotation which is nothing but roll pitch and yaw.

Nosography answered 8/8, 2017 at 21:3 Comment(3)
Perhaps this could be explained better, because if that line is changed, then recalculating the rotation matrix yields a rotation matrix different from the originally calculated one. Unless the order order of the unit matrices is changed, I think that "m.eulerAngles(0, 1, 2);" is correct.Doriedorin
No I'm quite sure it should be (2,1,0) the matrix multiplication above is not a conventional roll pitch yaw. The rotation should be R_yaw * R_pitch * R_roll not the other way around.Nosography
it is m.eulerAngles(2,1,0).Lublin

© 2022 - 2024 — McMap. All rights reserved.