Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/159.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何求特征基变换的变换矩阵_C++_Geometry_Eigen - Fatal编程技术网

C++ 如何求特征基变换的变换矩阵

C++ 如何求特征基变换的变换矩阵,c++,geometry,eigen,C++,Geometry,Eigen,我正在把一个程序移植到艾根 现在我必须重写一个方法,将3D变换矩阵从一个坐标系a(由原点和两个轴定义)返回到第二个坐标系(仍由原点和两个轴定义) 我想知道在Eigen中是否有找到那个矩阵的方法。我浏览了参考指南,但还没有找到任何有用的方法 详情如下: 我移植到Eigen的方法接受6个点(向量)(fr0,fr1,fr2,to0,to1,to2)。“fr0”是CS1(坐标系1)的原点,“fr1”是定义CS1轴的点,“fr2”是定义CS1第二轴的点;“to0”是CS2的起源,依此类推 无需特殊函数,

我正在把一个程序移植到艾根

现在我必须重写一个方法,将3D变换矩阵从一个坐标系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;
Matrix4f-M;

好的,我找到了解决方案,我把它贴在这里作为参考。我希望它也能对其他人有用

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


#包括
typedef特征::仿射3d变换;
类型定义特征::矢量3D点;
typedef-Eigen::Vector3d向量;
typedef特征::翻译;
转换FindTransformorMBetween2Cs(点fr0、点fr1、点fr2、点to0、点to1、点to2){
变换T,T2,T3=变换::标识();
向量3dx1,y1,z1,x2,y2,z2;
//坐标系“fr”的轴
x1=(fr1-fr0).normalized();//轴向量的反(酉向量)
y1=(fr2-fr0).normalized();
//坐标系的轴“到”
x2=(to1-to0).normalized();
y2=(to2-to0).normalized();
//从CS1到CS2的转换
//注意:如果fr0==(0,0,0)-->CS1==CS2-->T2=Identity

T2.linear()嗯,原点+两个轴并不是唯一定义坐标系的,第三个轴可以朝两个不同的方向移动。这是如何指定的?你是对的,我应该提到。在我们的代码中,Z只是定义为一个单位向量,如x.cross(y).normalized()。非常感谢你的回答Ggael。但实际上,我需要找到从一个坐标系a到另一个坐标系B的转换,用4个轴和2个原点作为参数。我的意思是:我已经有了一种方法,用“手工制作”代码;但我想知道Eigen是否有一些有用的函数用于此类计算。我在原始问题中添加了一些详细信息,请参阅工作代码
Affine3f M;
M.linear() << X, Y, X.cross(Y);
M.translation(O);
#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;

}