Eigen combine rotation and translation into one matrix

前端 未结 3 1095
野趣味
野趣味 2021-02-02 02:32

I have a rotation matrix rot (Eigen::Matrix3d) and a translation vector transl (Eigen::Vector3d) and I want them both together in a 4x4 transformation

3条回答
  •  迷失自我
    2021-02-02 02:57

    Another way is to use the Eigen::Transform.

    Let's take a example such as to implemente this affine transform ,

    #include 
    #include 
    using namespace Eigen;
    
    Matrix4f create_affine_matrix(float a, float b, float c, Vector3f trans)
    {
        Transform t;
        t = Translation(trans);
        t.rotate(AngleAxis(a, Vector3f::UnitX()));
        t.rotate(AngleAxis(b, Vector3f::UnitY()));
        t.rotate(AngleAxis(c, Vector3f::UnitZ()));
        return t.matrix();
    }
    

    You can also implemented as the following

    Matrix4f create_affine_matrix(float a, float b, float c, Vector3f trans)
    {
        Transform t;
        t = AngleAxis(c, Vector3f::UnitZ());
        t.prerotate(AngleAxis(b, Vector3f::UnitY()));
        t.prerotate(AngleAxis(a, Vector3f::UnitX()));
        t.pretranslate(trans);
        return t.matrix();
    }
    

    The difference between the first implementation and the second is like the difference between Fix Angle and Euler Angle, you can refer to this video.

提交回复
热议问题