c++ - 从 Eigen::AngleAxisd 到 Eigen::Vector3d 的转换
问题描述
我通过以下方式将旋转向量转换为旋转矩阵:
Eigen::Vector3d rotVec(-0.67925191, -1.35850382, -2.03775573);
Eigen::AngleAxisd rotAA(rotVec.norm(), rotVec.normalized());
Eigen::Matrix3d rotationMatrix = rotAA.matrix();
然后我想做从矩阵到向量的反向转换,我要做的是:
Eigen::AngleAxisd rotvec2(rotationMatrix);
然而,我无法将 Eigen::AngleAxisd 转换回 Eigen::Vector3d 并且 AngleAxisd 本身似乎只有一个角度和轴成员函数。
有谁知道我们该怎么做?
解决方案
AngleAxis
angle()
具有比和更多的成员函数axis()
。要么fromRotationMatrix(const MatrixBase< Derived > &mat)
或AngleAxis(const MatrixBase< Derived > &mat)
将做转换回来的第一步。见:https ://eigen.tuxfamily.org/dox/classEigen_1_1AngleAxis.html
然后使用乘积angle() * axis()
取回原始向量。
#include <Eigen/Dense>
#include <cstdlib>
int main()
{
using namespace Eigen;
using T = double;
Vector3<T> const rotVec{-0.67925191, -1.35850382, -2.03775573};
AngleAxis<T> const rotAA{rotVec.norm(), rotVec.normalized()};
Matrix3<T> const rotMat{rotAA.toRotationMatrix()};
#if 0
AngleAxis<T> rotAA2{};
rotAA2.fromRotationMatrix(rotMat);
#else
AngleAxis<T> const rotAA2{rotMat};
#endif
Vector3<T> const rotVec2{rotAA2.angle() * rotAA2.axis()};
bool const is_valid = rotVec.isApprox(rotVec2);
return is_valid ? EXIT_SUCCESS : EXIT_FAILURE;
}
推荐阅读
- azure-logic-apps - 如何检索多个逻辑应用程序的“已完成运行”计数
- php - ~/.composer/vendor/laravel/valet/server.php 中的权限被拒绝
- ruby-on-rails - 无法将 project_id 设置为嵌套路由中的数据库
- php - 无法使用 curl 或 file_get_contents 在单独的网站上执行命令
- android-layout - 如何实现以下 xml 布局?
- r - 在R中使用ggplot faceting进行地理空间映射?
- ios - 为没有父视图的视图调用“removeFromSuperView”
- java - 如何在 Java 中创建包含数据的对象
- android - 从联系人获取国家代码和手机号码
- create-react-app - 使用 Zeit Now 构建和部署,如何嵌入 Git 提交 SHA?