Eigen3中表示SLAM中的各种旋转表示

一、旋转矩阵

旋转矩阵直接可以使用Matrix类来定义。关于矩阵的操作可以看我之前写的内容:

Eigen库的基本使用说明_HHB791829200的博客-CSDN博客https://blog.csdn.net/HHB791829200/article/details/123417317

二、旋转轴

Eigen中有专门的几何变化的头文件Geometry。其中旋转轴在Eigen中通过一个选择度数和一个旋转轴表示:

AngleAxis<float> aa(angle_in_radian, Vector3f(ax,ay,az));使用这种方式定义需要声明类型,也可以使用默认设定好的类型如float 和double类型。

//3D rotation as an angle + axis
//AngleAxis<float> aa(angle_in_radian, Vector3f(ax,ay,az));

    Matrix3d roation_matrix=Matrix3d::Identity();
    Matrix3f roation_matrixf=Matrix3f::Identity();
    AngleAxisd roation_vector(M_PI/4,Vector3d(0,0,1));
    AngleAxis<float>  roation_vectorf(M_PI/4,Vector3f(0,0,1));

使用旋转矩阵和旋转轴对点(1,0,0)进行旋转:

//使用选择矩阵和选择向量对点(1,0,0)进行坐标变化

    Vector3d vector(1,0,0);
    Vector3d v_roation = roation_vector*vector;
    cout<<" this Angle Axis to (1,0,0) \n "<<v_roation<<endl;
    cout<<"this roation Matrix to (1,0,0) \n"<<roation_matrix*vector<<endl;

三、欧拉角

欧拉角的定义:

m = AngleAxisf (angle1, Vector3f::UnitZ ())
* AngleAxisf (angle2, Vector3f::UnitY ())
* AngleAxisf (angle3, Vector3f::UnitZ ());
​

这种表示方式比较麻烦如果我们知道旋转矩阵可以转换到欧拉角:

    Vector3d Euler_Angles=roation_matrix.eulerAngles(2,1,0);//ZYX顺序其中 Z轴表示2 Y轴表示1 X        
    //轴表示0
    cout<<"euler angle is  "<<Euler_Angles.transpose()<<endl;
    

四、变换矩阵

变换矩阵使用Isometry3d进行定义:可以开始定义一个单位阵之后只有旋转向量和平移来舒适化变化矩阵。

    Isometry3d T=Isometry3d::Identity();    //定义为3d,但实际为4d
    T.rotate(roation_vector);//设置旋转
    T.pretranslate(Vector3d(1,3,4));//设置平移

    cout<<" this transform is  \n "<<T.matrix()<<endl;
    //使用变换矩阵进行坐标变化

    Vector3d v_tranformed=T*vector;
    cout<<"use tranform : \n"<<v_tranformed<<endl;

五、四元数

Quaternion<float> q; q = AngleAxis<float>(angle_in_radian, axis);

当然四元素也可以用旋转矩阵初始化

q=Quaternion(Matrix_roation);

直接对四元数进行赋值一定要将设置为归一化下的坐标,q.normalize();

    Quaterniond q=Quaterniond(roation_vector);
    cout<<"quaterniond is"<<q.coeffs().transpose()<<endl;//前三个为虚部后一个为实部
    q=Quaterniond(roation_matrix);
    cout<<"quaterniond is"<<q.coeffs().transpose()<<endl;
    //使用四元数进行坐标变化
    Vector3d v_q=q*vector;
    cout<<" use quaterniond  \n"<<v_q<<endl;

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

每日亿学

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值