将Eigen中的多个变换组合成一个变换矩阵(Combining multiple transformations in Eigen into one transformation matrix)

编程入门 行业动态 更新时间:2024-10-23 20:20:40
将Eigen中的多个变换组合成一个变换矩阵(Combining multiple transformations in Eigen into one transformation matrix)

我在Eigen中进行了几次转换( Eigen::Vector3f )和旋转( Eigen::Quaternionf )。 我想按照我选择的顺序将所有这些转换组合成一个4x4转换矩阵Eigen::Matrix4f 。

例如,我想在A,B,C,D,E的顺序中应用以下转换:

Eigen::Vector3f translation_A; Eigen::Quaternionf rotation_B; Eigen::Quaternionf rotation_C; Eigen::Quaternionf rotation_D; Eigen::Vector3f translation_E;

实现这个最简单的方法是什么? 到目前为止,我一直将它们分别应用于我的最终数据,如下所示:

pcl::transformPointCloud(*cloud_in, *cloud_out, translation_A, IDENTITY_QUATERNION); pcl::transformPointCloud(*cloud_out, *cloud_out, ZERO_TRANSLATION, rotation_B); pcl::transformPointCloud(*cloud_out, *cloud_out, ZERO_TRANSLATION, rotation_C); pcl::transformPointCloud(*cloud_out, *cloud_out, ZERO_TRANSLATION, rotation_D); pcl::transformPointCloud(*cloud_out, *cloud_out, translation_E, IDENTITY_QUATERNION);

...但是必须有一个简单的(内置的)方法将这些使用Eigen的转换组合到最终的4x4转换矩阵中。

I have several transformations in Eigen, in the form of translations (Eigen::Vector3f) and rotations (Eigen::Quaternionf). I would like to combine all these transformations, in an order of my choosing, into a 4x4 transformation matrix Eigen::Matrix4f.

For example, I would like to apply the following transformations in the order A, B, C, D, E:

Eigen::Vector3f translation_A; Eigen::Quaternionf rotation_B; Eigen::Quaternionf rotation_C; Eigen::Quaternionf rotation_D; Eigen::Vector3f translation_E;

What is the simplest way of achieving this? I have so far been applying them individually to my final data like so:

pcl::transformPointCloud(*cloud_in, *cloud_out, translation_A, IDENTITY_QUATERNION); pcl::transformPointCloud(*cloud_out, *cloud_out, ZERO_TRANSLATION, rotation_B); pcl::transformPointCloud(*cloud_out, *cloud_out, ZERO_TRANSLATION, rotation_C); pcl::transformPointCloud(*cloud_out, *cloud_out, ZERO_TRANSLATION, rotation_D); pcl::transformPointCloud(*cloud_out, *cloud_out, translation_E, IDENTITY_QUATERNION);

...but there must be a simple (built-in?) way of combining these transformations using Eigen, into a final 4x4 transformation matrix.

最满意答案

Eigen文档中有一个很好的教程: 这里

在你的情况下,这应该看起来像:

Eigen::Vector3f trans_vec_A; //note that you have to create a Translation because multiplying a //Transform with a vector will _apply_ the transform to the vector Eigen::Translation<float,3> translation_A(trans_vec_A); Eigen::Quaternionf rotation_B; Eigen::Quaternionf rotation_C; Eigen::Quaternionf rotation_D; Eigen::Vector3f trans_vec_E; Eigen::Translation<float,3> translation_E(trans_vec_E); Eigen::Transform<float,3,Affine> combined = translation_A * rotation_B * rotation_C * rotation_D * translation_E;

注意

combined = A*B*C*D*E

所以combined应用于矢量v是

combined*v = A*B*C*D*E*v = A*(B*(C*(D*(E*v))))

即首先应用E ,然后应用D ,依此类推。 在我看来,这是正确的顺序,但这可能是一个品味问题。

There is a good tutorial in the Eigen docs: here

In your case, this should look like:

Eigen::Vector3f trans_vec_A; //note that you have to create a Translation because multiplying a //Transform with a vector will _apply_ the transform to the vector Eigen::Translation<float,3> translation_A(trans_vec_A); Eigen::Quaternionf rotation_B; Eigen::Quaternionf rotation_C; Eigen::Quaternionf rotation_D; Eigen::Vector3f trans_vec_E; Eigen::Translation<float,3> translation_E(trans_vec_E); Eigen::Transform<float,3,Affine> combined = translation_A * rotation_B * rotation_C * rotation_D * translation_E;

Note that

combined = A*B*C*D*E

so combined applied to a vector v is

combined*v = A*B*C*D*E*v = A*(B*(C*(D*(E*v))))

that is, E is applied first, then D, and so on. In my mind, this is the correct order, but that may be a matter of taste.

更多推荐

本文发布于:2023-07-29 20:11:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1319410.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:组合   多个   矩阵   Eigen   Combining

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!