首页 > 解决方案 > 特征,链接平移和旋转

问题描述

在 Eigen3 中,我需要先进行旋转,然后再进行平移。

请注意,转换设置为身份以正确重置其值。

我可以这样做,但旋转改变了参考轴,我的翻译是错误的。

auto transform_rotation ( Transform <double, 3, Affine> &t, const double rotate_x, const double rotate_y, const double rotate_z )->void {


        if ( rotate_x ){

                auto p = AngleAxisd( rotate_x, Vector3d::UnitX() );
                t *= p.matrix();

        }

        if ( rotate_y ){

                auto p = AngleAxisd( rotate_y, Vector3d::UnitY() );
                t *= p.matrix();

        }

        if ( rotate_z ){

                auto p = AngleAxisd( rotate_z, Vector3d::UnitZ() );
                t.rotate( p.matrix() );

        }
}

auto transform_translation ( Transform <double, 3, Affine> &t, const double translate_x, const double translate_y, const double translate_z )-> void {

                auto n = Translation3d( translate_x, translate_y, translate_z );

                // t.translate( n.translation() );
                t *= n;

}

当旋转发生时,对应于该点的新旋转进行以下平移。

我想要一致的 x、y 和 z 轴。我认为我的旋转功能把一切都搞砸了。

我想要什么:如果我需要应用 az 旋转,比如 90°,然后在 x 轴上平移 5 个单位,我应该有以下代码:

...
Transform<double,3,Affine> t;
t.setidentity();

transform_rotation(t, 0,0,(90 * M_PI / 180);
transform_translation(t, 5,0,0);// right now, I must do (t, 0,-5,0);
.. 
Vector3d point{1,1,0};
point *= t;
...

我怎样才能做到这一点 ?我错过了什么?谢谢

2021 年 10 月 29 日更新

好的,我终于得到了这样的代码:

 auto y = Translation3d(vector1.x(), vector1.y(), 0);
 auto z = AngleAxisd( angle, Vector3d::UnitZ() );
 t =  y * z;

它有效。没有我想的那么干净,但就是这样。。

标签: rotationtranslationeigentransformationeigen3

解决方案


推荐阅读