gpt4 book ai didi

c++ - 如何用 Eigen 找到基变化的变换矩阵

转载 作者:太空狗 更新时间:2023-10-29 23:52:33 25 4
gpt4 key购买 nike

我正在将程序移植到 Eigen。

现在我必须重写一个方法,该方法将 3D 变换矩阵从一个坐标系 A(由其原点和两个轴定义)返回到第二个坐标系,仍然由原点和两个轴定义。

我想知道 Eigen 中是否有找到该矩阵的方法。我浏览了引用指南,但我还没有找到任何有用的方法......


更多细节:

我移植到 Eigen 的方法接受 6 个点( vector )(fr0、fr1、fr2、to0、to1、to2)。 “fr0”是CS1(坐标系1)的原点,“fr1”是定义CS1的一个轴的点,“fr2”是定义CS1的第二个轴的点; “to0”是CS2的起源,依此类推……

最佳答案

好的,我找到了解决方案,我把它贴在这里以供引用。我希望它对其他人也有用。

实际上 ggael 的回答触发了正确的解决方案,非常感谢他并为他 +1。


#include <Eigen/Geometry>

typedef Eigen::Affine3d Transformation;
typedef Eigen::Vector3d Point;
typedef Eigen::Vector3d Vector;
typedef Eigen::Translation<double,3> Translation;

Transformation findTransformBetween2CS(Point fr0,Point fr1,Point fr2,Point to0,Point to1,Point to2) {

Transformation T, T2, T3 = Transformation::Identity();
Vector3d x1,y1,z1, x2,y2,z2;

// Axes of the coordinate system "fr"
x1 = (fr1 - fr0).normalized(); // the versor (unitary vector) of the (fr1-fr0) axis vector
y1 = (fr2 - fr0).normalized();

// Axes of the coordinate system "to"
x2 = (to1 - to0).normalized();
y2 = (to2 - to0).normalized();

// transform from CS1 to CS2
// Note: if fr0==(0,0,0) --> CS1==CS2 --> T2=Identity
T2.linear() << x1, y1, x1.cross(y1);

// transform from CS1 to CS3
T3.linear() << x2, y2, x2.cross(y2);

// T = transform to CS2 to CS3
// Note: if CS1==CS2 --> T = T3
T.linear() = T3.linear() * T2.linear().inverse();


T.translation() = t0;

return T;

}

灵感也来自这篇帖子:

https://gamedev.stackexchange.com/questions/26084/transform-between-two-3d-cartesian-coordinate-systems

关于c++ - 如何用 Eigen 找到基变化的变换矩阵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15252919/

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