在另一个坐标系中查找点的坐标

时间:2015-01-13 06:34:23

标签: c++ matrix rotation translation

我长期以来一直在努力解决这个非常简单的问题,但我似乎无法理解如何解决这个问题。

我有2个坐标系。在原点,比例,旋转方面,每个都不同于另一个。我必须在任何一个坐标系上找到任何随机点的x,y,z坐标。基本上是基础的变化。坐标系的构建如下:

glm::mat4 matA = glm::mat4(); //Build matrix with identity
matA = matA*rotationA;     //Rotate
matA = matA*translationA;  //Translate


glm::mat4 matB = glm::mat4(); //Build matrix with identity
matB = matB*rotationB;     //Rotate
matB = matB*translationB;  //Translate

vec3 pointOnMatA = vec3( 5, 5, 5 );
//Find this point but on the matrixB coordinate system
vec3 pointOnMatB = ???

2 个答案:

答案 0 :(得分:1)

就数学而言,它应该是

pointOnMatB = matB*(inverseMatA*pointOnMatA);

至于评论中提到的问题:我不熟悉glm,但矩阵向量乘法要求所有组件具有相同的顺序(mat4vec4)。 如果您使用的是openGL和齐次坐标系,则矢量的前三个元素是X,Y,Z,最后一个分量(W)应该是1.这里有一个适合您的读物:

http://www.tomdalling.com/blog/modern-opengl/explaining-homogenous-coordinates-and-projective-geometry/

答案 1 :(得分:1)

在不同坐标系之间转换点的坐标的想法首先是找到对齐坐标框架的转换,然后将相同的转换应用于该点。例如,如果我们有两个坐标系A和B,并且我们有一个坐标在坐标系A中给出的点,找到将坐标框B与A对齐的变换,然后将相同的变换应用于该点并获得点&# 39;坐标系B中的坐标。