Eigen位姿表示

 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头文件

  • 2
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值