Eigen的几何模块
2017-03-31 21:42
447 查看
#include <iostream> #include <cmath> using namespace std; #include <Eigen/Core> #include <Eigen/Geometry> int main( ) { Eigen::Matrix3d rotation_matrix = Eigen::Matrix3d::Identity( ); Eigen::AngleAxisd rotation_vector( M_PI / 2, Eigen::Vector3d( 0, 0, 1 ) ); cout << "rotation_matrix = \n" << rotation_vector.matrix( ) << endl; // 转换成矩阵 rotation_matrix = rotation_vector.toRotationMatrix( ); // 直接赋值 // 用AngleAxis进行坐标变换 Eigen::Vector3d v( 1, 0, 0 ); Eigen::Vector3d v_rotated = rotation_vector * v; cout << "( 1, 0, 0 ) after rotation = \n" << v_rotated << endl; // 用旋转矩阵进行坐标变换 v_rotated = rotation_matrix * v; cout << "( 1, 0, 0 ) after rotation = \n" << v_rotated << endl; // 将旋转矩阵转换成欧拉角 Eigen::Vector3d euler_angles = rotation_matrix.eulerAngles( 0, 1, 2 ); // x-y-z 顺序,即rpy cout << "roll pitch yaw = \n" << euler_angles << endl; // 用Eigen::Isometry表示欧氏变换矩阵 Eigen::Isometry3d T = Eigen::Isometry3d::Identity( ); // 三维变换矩阵 T.rotate( rotation_vector ); // 旋转部分赋值 T.pretranslate( Eigen::Vector3d( 1, 0, 0 ) ); // 设置平移向量 cout << "Transform matrix = \n" << T.matrix( ) << endl; // 用欧氏变换矩阵进行坐标变换,此处的乘法运算符是重载意义上的 Eigen::Vector3d v_transformed = T * v; // 相当于R*v + t cout << "v transformed = \n" << v_transformed << endl; // 相应地,仿射变换和摄影变换,使用Eigen::Affine3d和Eigen::Projective3d // 直接将旋转向量赋值给四元数,反之亦然 Eigen::Quaterniond q = Eigen::Quaterniond( rotation_vector ); cout << "quaternion = \n" << q.coeffs( ) << endl; // Eigen的存储顺序为(x,y,z,w),实部为w // 直接将旋转矩阵赋值给四元数 q = Eigen::Quaterniond( rotation_matrix ); cout << "quaternion = \n" << q.coeffs( ) << endl; // 用四元数旋转一个向量,使用重载过的乘法运算符 v_rotated = q * v; // 相当于qvq^{-1} cout << "( 1, 0, 0 ) after rotation = \n" << v_rotated << endl; return 0; }
相关文章推荐
- 视觉SLAM——第三章 Eigen几何模块Geometry使用 四元素 欧式变换矩阵
- PCL中Sample_consensus模块支持的几何模型
- Python模块学习系列(6)----Tkinter(几何布局管理)
- PCL中Sample_consensus模块支持的几何模型
- Eigen集合模块学习(角轴,位姿,欧拉角,四元数)--参考SLAM十四讲3.6
- Gmesh的几何模块
- 搭建基于ASP.NET 2.0的DNN 4.X模块开发环境及模块实例(1)
- 计算几何与计算机图形学方面的一些资源及源代码
- nginx 源码学习笔记(二十一)—— event 模块(二) ——事件驱动核心ngx_process_events_and_timers
- Android网络编程之一个Android下菜单系统模块的实现(客户端—更新桌号)
- 图像BPR,MSE,RMSE,PSNR求取模块
- 第9周项目6年龄几何
- 【构建Android缓存模块】(三)Controller & 异步图片加载
- python加密模块使用,aes128,ecb模式
- L298N模块
- node.js的request模块详解
- 关于python scrapy执行爬虫出现的 ImportError: DLL load failed:找不到指定的模块
- [高级软件工程实验]用callback增强链表模块来实现命令行菜单小程序V2.8
- python笔记-模块发布及安装
- 绿色SQL Server原理(10)VB6启动停止模块[GreenSQL.bas]