Eigen学习笔记2--旋转、平移

1.Eigen 与旋转、平移有关的类

Eigen::Matrix4f
Affine3f (有旋转和平移成员)
Quaternionf(四元数)
AngleAxisf(旋转轴
Translation3f

Affine3f中有rotation和translation分量,但Matrix4f中没有。

1、Matrix4f到Affine3f:


Matrix4f m4f_transform;

Eigen::Transform a3f_transform (m4f_transform);


2、Affine3f到Matrix4f:


Eigen::Transform a3f_transform ;

Matrix4f m4f_transform=a3f_transform.matrix();

2.变换矩阵T

此处参考了https://blog.csdn.net/weixin_38275649/article/details/80968364
方法一 #1: 使用普通矩阵 Matrix4f
先造个单位矩阵,在把旋转矩阵(3*3)逐个设置,最后设置平移(第四列)
Eigen::Matrix4f transform_1 = Eigen::Matrix4f::Identity();
// 定义一个旋转矩阵 (见 https://en.wikipedia.org/wiki/Rotation_matrix)
float theta = M_PI/4; // 弧度角
transform_1 (0,0) = cos (theta);
transform_1 (0,1) = -sin(theta);
transform_1 (1,0) = sin (theta);
transform_1 (1,1) = cos (theta);
// 在 X 轴上定义一个 2.5 米的平移.
transform_1 (0,3) = 2.5;
// 打印变换矩阵
std::cout << transform_1 << std::endl;

方法二 #2: 使用 Affine3f,专用于旋转平移变换矩阵打造的映射
Eigen::Affine3f transform_2 = Eigen::Affine3f::Identity();
// 在 X 轴上定义一个 2.5 米的平移.
transform_2.translation() << 2.5, 0.0, 0.0;
// 和前面一样的旋转; Z 轴上旋转 theta 弧度,AngelAxisf(theta, axis)得到一个3*3的旋转矩阵
transform_2.rotate (Eigen::AngleAxisf (theta, Eigen::Vector3f::UnitZ()));

你可能感兴趣的:(各种库学习)