【问题标题】:Howto make a roto-translation in PCL if I have the angle and the axis?如果我有角度和轴,如何在 PCL 中进行旋转平移?
【发布时间】:2024-06-26 06:30:02
【问题描述】:

我想对点云进行平移,目前我有轴的矢量,也有角度。我可以自动构造矩阵还是必须像this一样手动计算?

在 PCL example 中,他们使用他们构建的 MAtrix 4x4,所以我希望有人知道自动获取此矩阵的方法。

【问题讨论】:

    标签: c++ image-rotation printer-control-language


    【解决方案1】:

    在您给出的example 中,已经有一种更简单的构造变换矩阵的方法。不仅包括旋转,还包括移动(即平移)。

     /*  METHOD #2: Using a Affine3f
        This method is easier and less error prone
      */
      Eigen::Affine3f transform_2 = Eigen::Affine3f::Identity();
    
      // Define a translation of 2.5 meters on the x axis.
      transform_2.translation() << 2.5, 0.0, 0.0;
    
      // The same rotation matrix as before; tetha radians arround Z axis
      transform_2.rotate (Eigen::AngleAxisf (theta, Eigen::Vector3f::UnitZ())); 
    

    【讨论】:

    • 我已经看到了那部分,我想知道如何添加向量,但我终于在 Eigen 文档中找到了它,而不是在 PCL 文档中。谢谢@Oncaphilis!
    【解决方案2】:

    示例中缺少的是,在 Eigen::AngleAxisf 的第二个参数中,我们应该像这样添加轴:

     //Eigen::Transform t;
    Eigen::Vector3f axis(v_Ux,v_Uy,v_Uz);
     Eigen::Affine3f transform_2 = Eigen::Affine3f::Identity();
    // Define a translation of 2.5 meters on the x axis.
    transform_2.translation() << 2.5, 0.0, 0.0;
    Eigen::AngleAxis<float> rot(angle,axis);
    transform_1.rotate(rot);
    

    我还必须把它写成 2 行,因为我在编译时遇到了模板错误。我刚刚添加了浮点数,它起作用了!

    【讨论】: