SLAM学习之Eigen基础矩阵表示

#include
#include

• 旋转矩阵(3 × 3): Eigen::Matrix3d。
• 旋转向量(3 × 1): Eigen::AngleAxisd。
• 欧拉角(3 × 1): Eigen::Vector3d。
• 四元数(4 × 1): Eigen::Quaterniond。
• 欧氏变换矩阵(4 × 4): Eigen::Isometry3d。
• 仿射变换(4 × 4): Eigen::Affine3d。
• 射影变换(4 × 4): Eigen::Projective3d。
• 矩阵表示 : Eigen::Matrix name。 name << (1,1,1,1)
•动态矩阵 :Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > matrix_dynamic。

旋转向量 -> 旋转矩阵 -> (欧拉角)旋转向量、旋转矩阵 -> 四元数

旋转向量使用 AngleAxis, 它底层不直接是 Matrix ,但运算可以当作矩阵(因为重载了运算符)
Eigen::AngleAxisd rotation_vector ( M_PI/4, Eigen::Vector3d ( 0,0,1 ) ); // 沿 Z 轴旋转 45 度
rotation_matrix = rotation_vector.toRotationMatrix();
Eigen::Vector3d v_rotated = rotation_vector * v;
// 欧拉角:可以将旋转矩阵直接转换成欧拉角
Eigen::Vector3d euler_angles = rotation_matrix.eulerAngles ( 2,1,0 ); // ZYX 顺序,即 yaw pitch roll
顺序
// 欧氏变换矩阵使用 Eigen::Isometry
Eigen::Isometry3d T=Eigen::Isometry3d::Identity(); // 虽然称为 3d ,实质上是 4* 4 的矩阵
T.rotate ( rotation_vector ); // 按照 rotation_vector 进行旋转
T.pretranslate ( Eigen::Vector3d ( 1,3,4 ) ); // 把平移向量设成 (1,3,4)
Eigen::Vector3d v_transformed = Tv; // 相当于 Rv+t
// 四元数
q = Eigen::Quaterniond ( rotation_matrix );
v_rotated = q*v;

你可能感兴趣的:(c++,SLAM,slam,c++)