好吧,我找到了解決方案,我張貼在這裏以供參考。我希望它對其他人也有用。
其實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
呃,產地+兩軸不能唯一地確定一個座標系,第三軸可以去在兩個不同方向。這是如何指定的? – us2012 2013-03-06 16:42:19
你說得對,我應該提到。在我們的代碼中,Z被簡單地定義爲一個單位向量x.cross(y).normalized()。 – rmbianchi 2013-03-07 16:19:29