c++ - 使用 Eigen 库从旋转矩阵滚动俯仰和偏航

标签 c++ matrix eigen rotational-matrices euler-angles

我需要从旋转矩阵中提取滚动俯仰偏航角,并且我想确保我所做的是正确的。

    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));

这样对吗?因为我在这里阅读: http://eigen.tuxfamily.org/dox/group__Geometry__Module.html#gad118fececd448d7485ffea4858775e5a

当它在描述的末尾说,其中定义了角度的间隔时,我有点困惑。

最佳答案

我想这就是您要找的。取决于我们如何使用 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;

感谢您的引用!我也是先用Eigen。简直省事多了!

关于c++ - 使用 Eigen 库从旋转矩阵滚动俯仰和偏航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27508242/

相关文章:

c++ - OpenGL 矩阵乘法 C++

hadoop - 具有 6 到 7 个节点硬件配置的分布式 Spark 和 HDFS 集群

c++ - 如何将 ProductReturnType 转换为矩阵?

c++ - Eigen不同方法(LDLT、​​SVD、QR)同一个矩阵的不同解

C++ 转换运算符到 chrono::duration - 适用于 c++17 但不适用于 C++14 或更低版本

C++ 类型转换 : benefit of using explicit casts?

c++ - 如何将复杂的 C++ XCode 项目转换为 Cocoa 应用程序?

matlab - 如何在 Matlab 中多次加入同一个矩阵以制作一个大矩阵?

c++ - Eigen::AutoDiff 的 Eigen::Spline 的错误模板参数

c++ - 可变参数模板参数的元迭代