[英]how to find the transformation matrix of a change of basis with Eigen
我正在向Eigen移植一個程序。
現在我必須重寫一個方法,將三維變換矩陣從一個坐標系A(由其原點和兩個軸定義)返回到第二個坐標系,仍然由原點和兩個軸定義。
我想知道Eigen中是否有一種方法可以找到該矩陣。 我瀏覽了參考指南,但我還沒有找到任何有用的方法......
更多細節:
我移植到Eigen的方法接受6個點(向量)(fr0,fr1,fr2,to0,to1,to2)。 “fr0”是CS1(坐標系1)的原點,“fr1”是定義CS1的軸的點,“fr2”是定義CS1的第二軸的點; “to0”是CS2的起源,依此類推......
不需要特殊功能,只需使用逗號初始化程序:
Matrix4f M;
M << X, Y, X.cross(Y), O,
0, 0, 0, 1;
這假設兩個軸X和Y是整體的並且是正交的。 O是起源。
您還可以查看幾何模塊以獲取更高級的空間轉換類和函數,例如Transform <>類。 以下是使用Affine3f typedef而不是原始矩陣的相同示例:
Affine3f M;
M.linear() << X, Y, X.cross(Y);
M.translation(O);
好的,我找到了解決方案,我在這里發布以供參考。 我希望它對其他人也有用。
實際上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;
}
靈感也來自這篇文章:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.