本征将旋转和平移组合为一个矩阵 [英] Eigen combine rotation and translation into one matrix
问题描述
我有一个旋转矩阵rot
(Eigen :: Matrix3d)和一个平移矢量transl
(Eigen :: Vector3d),我希望它们都一起放在4x4的转换矩阵中.我只是为了我的一生,无法弄清楚如何在Eigen中做到这一点.我认为可以以某种方式使用Affine,但我不知道它是如何工作的.
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 matrix. I just for the life of me can't figure out how to do this in Eigen. I think Affine can be used somehow but I don't understand how it works.
本质上,我想要组合如何在Eigen中翻译矩阵(4x4)? /a>和在Eigen中乘以变换和矩阵类型
我的代码(由于我不了解Affine的工作原理而无法编译)如下所示:
My code (that doesn't compile as I don't understand how Affine works) looks like this:
Eigen::Affine3d r(rot);
Eigen::Affine3d t(transl);
Eigen::Matrix4d m = t.matrix();
m *= r.matrix();
推荐答案
另一种方法是执行以下操作:
Another method is to do the following:
Eigen::Matrix3d R;
// Find your Rotation Matrix
Eigen::Vector3d T;
// Find your translation Vector
Eigen::Matrix4d Trans; // Your Transformation Matrix
Trans.setIdentity(); // Set to Identity to make bottom row of Matrix 0,0,0,1
Trans.block<3,3>(0,0) = R;
Trans.block<3,1>(0,3) = T;
此方法从字面上将Rotation矩阵复制到前3行和第3列,并将平移向量复制到第4列.然后将右下角的矩阵条目设置为1. 您的最终矩阵将如下所示:
This method literally copies the Rotation matrix into the first 3 rows and columns and the translation vector to the 4th column. Then sets the bottom right matrix entry to 1. You final matrix will look like:
R R R T
R R R T
R R R T
0 0 0 1
其中R是旋转矩阵中的对应值,T是平移向量中的值.
where R are the corresponding values from the rotation matrix and T the values from the Translation vector.
这篇关于本征将旋转和平移组合为一个矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!