gpt4 book ai didi

c++ - Eigen 将旋转和平移合并为一个矩阵

转载 作者:可可西里 更新时间:2023-11-01 17:21:30 26 4
gpt4 key购买 nike

我有一个旋转矩阵 rot (Eigen::Matrix3d) 和平移 vector transl (Eigen::Vector3d) 我希望它们一起进行 4x4 变换矩阵。我只是为了我的生活无法弄清楚如何在 Eigen 中做到这一点。我认为仿射可以以某种方式使用,但我不明白它是如何工作的。

基本上我想要 How translation a matrix(4x4) in Eigen? 的组合和 Multiplying Transform and Matrix types in Eigen

我的代码(无法编译,因为我不明白仿射的工作原理)如下所示:

Eigen::Affine3d r(rot);
Eigen::Affine3d t(transl);
Eigen::Matrix4d m = t.matrix();
m *= r.matrix();

最佳答案

另一种方法是执行以下操作:

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;

此方法从字面上将旋转矩阵复制到前 3 行和前 3 列,并将平移 vector 复制到第 4 列。然后将右下矩阵条目设置为 1。您最终的矩阵将如下所示:

R R R T
R R R T
R R R T
0 0 0 1

其中 R 是旋转矩阵的对应值,T 是平移 vector 的值。

关于c++ - Eigen 将旋转和平移合并为一个矩阵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25504397/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com