Given a 4x4 homogeneous matrix, how can i get 3D world coords?

痴心易碎 提交于 2019-12-23 15:20:31

问题


So i have an object which is getting rotated then translated and rotated again. I am storing a matrix of these translations as an object member. Now when i come to object picking i need to know the 3D world coords of this object.

Currently i have been able to get the position of the object like so

coords[0] = finalMatrix[12];

coords[1] = finalMatrix[13];

coords[2] = finalMatrix[14];

This is giving me the correct positions of the objects but i want to take the rotations into account as well.

Any help would be great...


回答1:


The matrix is a 4x4 matrix, but as you've just got a single dimensional matrix it appears that the elements are arranged as follows:

[0]  [4]  [8]   [12]
[1]  [5]  [9]   [13]
[2]  [6]  [10]  [14]
[3]  [7]  [11]  [15]

The rotation part is the top left 3x3 matrix see here, so in your case it would be elements [0]-[2], [4]-[6] and [8]-[10]




回答2:


http://www.euclideanspace.com/maths/geometry/affine/matrix4x4/index.htm - here is the explanation how the 4x4 matrices work. The first minor 3x3 - is a rotation matrix. The last column except last element is a translation vector. And element[4, 4] is a scale factor. Read more about this at the link




回答3:


So I am an idiot... i had it correct in the first place. All i needed was the position data in [12][13][14]. I had a couple stupid bugs in my code, one of which was not having enough iterations on my ray intersection...All sorted now lol im kicking myself..haha thanks anyway guys!!



来源:https://stackoverflow.com/questions/4791710/given-a-4x4-homogeneous-matrix-how-can-i-get-3d-world-coords

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!