Eigen位姿表示

news/2024/7/5 4:18:15

 Eigen有多种位姿表示方法,下面依次介绍

1. Isometry3d

// 虽然称为3d,实质上是4*4的矩阵,齐次坐标
Eigen::Isometry3d Tc1w = Eigen::Isometry3d::Identity();// 按照rotation_matrix进行旋转
Tc1w.rotate(rotation_matrix);// 把平移向量设成t
Tc1w.pretranslate(t);                                                  // 获取旋转矩阵
Eigen::Matrix3d rotation = Tc1w.rotation();// 获取平移向量
Eigen::Vector3d position = Tc1w.translation();

注意:

使用前一定要初始化,否则后面的设置无法生效;

函数pretranslate(p)就是把平移t设置到位姿矩阵之中,即实现的是t = p

函数translate(t)先用把位姿用到到t上,再把得到的结果设置到位姿矩阵之中,即实现的是t = Rp + t

2. 旋转向量AngleAxisd

Eigen::AngleAxisd rotation_vector(alpha, Vector3d(x,y,z))

2.1. 旋转向量转旋转矩阵

Eigen::Matrix3d rotation_matrix;
rotation_matrix = rotation_vector.matrix();
rotation_matrix = rotation_vector.toRotationMatrix();

2.2. 旋转向量转欧拉角

Eigen::Vector3d eulerAngle = rotation_vector.matrix().eulerAngles(2,1,0);

2.3. 旋转向量转四元数

Eigen::Quaterniond quaternion(rotation_vector);

3. 四元数Quaterniond

3.1. 构造

# 使用四个数构造,注意四元数的顺序
Eigen::Quaterniond quaternion(w, x, y, z);# 使用指针构造,注意四元数的顺序,与上面不同
Eigen::Matrix<double, 4, 1> pose_vec;
pose_vec << x, y, z, w;
Eigen::Quaterniond quaternion(pose_vec.data());# 使用旋转矩阵构造
Eigen::Matrix3d rotation;
Eigen::Quaterniond (rotation);

3.2. 映射

Eigen::Matrix<double, 4, 1> pose_vec;
pose_vec << x, y, z, w;# 二者共享内存
Eigen::Map<Eigen::Quaterniond> q(q_vec.data());

3.3. 其它函数

# 转旋转矩阵
q.toRotationMatrix();# 求逆
q.inverse()# 归一化
q.normalize()

4. 欧拉角

欧拉角转旋转矩阵

Eigen::AngleAxisd roll_matrix(Eigen::AngleAxisd(nav.roll, Eigen::Vector3d::UnitX()));
Eigen::AngleAxisd pitch_matrix(Eigen::AngleAxisd(nav.pitch, Eigen::Vector3d::UnitY()));
Eigen::AngleAxisd yaw_matrix(Eigen::AngleAxisd(nav.yaw, Eigen::Vector3d::UnitZ()));
Eigen::Matrix rotation_matrix = (yaw_matrix * pitch_matrix * roll_matrix).matrix();

参考文献

Eigen中四元数、欧拉角、旋转矩阵、旋转向量之间的转换_yang__jing的博客-CSDN博客_eigen 四元数转旋转矩阵

Eigen的使用总结2——geometry_reason的博客-CSDN博客_eigen::isometry3d

Eigen(2) 模块与头文件_CSDN1HAO的博客-CSDN博客_eigen头文件


http://lihuaxi.xjx100.cn/news/248475.html

相关文章

动软代码生成V2.74模版简介

最近发现很多人用动软代码生成&#xff0c;确实方便&#xff0c;有些经验记录下&#xff0c;以后查看回顾。 ..\Maticsoft\Codematic2\Template\TemplateFile 为模板文件夹&#xff0c;直接在目录下新建文件夹【我的自定义模版】,有个【模版示例.cmt】也直接复制到自定义文件下…

mysql (双主,互主)

Master-Master&#xff08;双主&#xff09; 1、测试环境 Master/Slave Master1/Slave1 IP 192.168.1.13 192.168.1.10 为了保持干净的环境&#xff1a;两边服务器 rm -rf /var/lib/mysql/* service mysqld re…

6. matlab中case语句的使用

&#xff08;1&#xff09;单个的就如同C语言中的一样&#xff0c;不过在和switch使用的时候case后不用接&#xff1a; n input(Enter a number: );switch ncase -1disp(negative one)case 0disp(zero)case 1disp(positive one)otherwisedisp(other value) end&#xff08;2&a…

matplotlib使用笔记

1. 简要介绍 matplotlib是一个用于画图的Python开源库&#xff0c;提供了强大的画图功能 与MATLAB相比 功能类似&#xff0c;但使用上逊于MATLAB。尤其在数据量很大时&#xff0c;画出的图卡顿很严重&#xff0c;远逊于MATLAB 与Excel相比 如果只画一次图&#xff0c;Excel更…

Bootstrap3.x - 源代码分析

参照http://v3.bootcss.com/css/ 文档与源代码colors 比较全面定义总结有意义的颜色。所有uI要用的颜色&#xff0c;都先从已定义的读&#xff0c;这样保证样式的同一性&#xff0c;而且方便以后开发主题库。(建议想自己写css模块的&#xff0c;可以参考一下bootstrap里颜色定义…

Word 2003文件保存和另存为操作是否熟练掌握的有关测试

提出问题本文内容不仅适用于Word&#xff0c;对于其他的文档&#xff08;文字、图形、动画、声音等&#xff09;编辑软件基本通用。对于操作上述各种编辑软件时&#xff0c;大家都应该注意到&#xff0c;我们第一次保存文件时系统出现的是“另存为”对话框。此后&#xff0c;再…

7.matlab中使用@ + “函数名”

总是会面临&#xff0c;根据选择的不同的值&#xff0c;获得不同 函数。就类似于switch 中的问题 switch Fcase F1fobj F1;lb-100;ub100;dim30;case F2fobj F2lb-10;ub10;dim30;end function o F1(x) % o sum(x.^2); This is the advantage of matrix osum((x)…

pyspatialite

1. 头文件 import psycopg2 2. 数据库连接 2.1. 本地数据库连接 connect sqlite3.connect(file_name) connect.load_extension(mod_spatialite) cursor connect.cursor() 2.2. 远程数据库连接 connect psycopg2.connect(databasedatabase, useruser, passwordpassword…