假设我有一个 3 维框架,旋转 roll = 0,pitch = 0 和 yaw = 0,分别关于 x、y 和 z 轴。
我希望框架绕 x 轴旋转 3.14159 (Pi) 或 roll = Pi。
下面是上述情况的代码。
问题是,当我想将旋转矩阵转换回滚动、俯仰和偏航时,代码给出了不同的答案。
结果不是 roll = Pi,而是 roll = 0,pitch = pi,yaw = pi。
我认为 Peter Corke 在 Matlab 上的 RVC 工具箱给出了正确的答案。
也许我的程序有问题,或者 Eigen 中的 eulerAngles 工作方式不同?请帮忙。
代码:
#include <iostream>
#include <Eigen/Dense>
const double PI = 3.14159265359;
int main()
{
using ::Eigen::AngleAxisd;
using ::Eigen::Matrix3d;
using ::Eigen::Vector3d;
using ::std::cout;
using ::std::endl;
Matrix3d R,Rx;
R = AngleAxisd(PI, Vector3d::UnitX())
* AngleAxisd(0, Vector3d::UnitY())
* AngleAxisd(0, Vector3d::UnitZ());
Rx = AngleAxisd(PI, Vector3d::UnitX());
cout << R << endl << endl;
cout << Rx << endl << endl;
Vector3d ea = R.eulerAngles(0,1,2);
Vector3d eax = Rx.eulerAngles(0,1,2);
cout << ea << endl << endl;
cout << eax << endl << endl;
std::cin.ignore();
return 0;
}
输出(我将小到零的数字四舍五入):
1 0 0
0 -1 0
0 0 -1
1 0 0
0 -1 0
0 0 -1
0
3.14159
3.14159
0
3.14159
3.14159
最佳答案
欧拉角不是唯一的。在您的 XYZ 约定中,(0, pi, pi)
和 (pi,0,0)
都表示相同的旋转,并且都是正确的。 Eigen::eulerAngles
方法始终选择最小化第一角。
关于c++ - 关于 Eigen C++ 库的 EulerAngles 转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33895970/