C++ 使用特征库从旋转矩阵滚动俯仰和偏航
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27508242/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Roll pitch and yaw from Rotation matrix with Eigen Library
提问by desmond13
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
那是对的吗?因为我在这里阅读: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.
当它在描述的末尾说,在哪个间隔中定义了角度时,我有点困惑。
回答by TSL_
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
我想这就是你要找的。取决于我们如何使用
m.eulerAngles(0, 1, 2)
;这是获得 rotx, roty, rotz 的代码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!
谢谢您的参考!我也首先使用 Eigen。简直是省了很多工作啊!
回答by Rachit Bhargava
The answer by Shawn Le is correct but I think the line should be
Shawn Le 的回答是正确的,但我认为这条线应该是
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.
然后ea
将按该顺序保持偏航俯仰和滚转值。ZYX 欧拉角旋转等价于 XYZ 固定轴旋转,只不过是横滚俯仰和偏航。