如何仅翻转变换矩阵的一个轴? [英] How to flip only one axis of transformation matrix?
问题描述
我有一个4x4的转换矩阵.但是,在尝试了变换之后,我注意到Y轴的移动和正相反.其余的是正确的.
我从其他API得到了这个矩阵,所以大概是坐标系的差异.那么,如何翻转转换矩阵的轴?
如果仅平移,我可以在Y平移上添加减号,但是我不知道只有一个轴的反向旋转,因为所有旋转都在同一3x3区域中表示.我认为可能会有某种方式甚至同时影响平移和旋转.(真正地翻转轴)
我很确定您要查找的操作是在更改坐标系的同时保持Z向上或Y向上.在这种情况下,请尝试将矩阵第二列(或行)的所有元素设置为相反的元素.
这个问题对于Math StackExchange会更好.首先,
给定一个从相同旋转顺序得出的矩阵,结果矩阵如下,其中alpha是X角,beta是Y角,gamma是Z角:
您可以从此矩阵得出每个轴角的各个分量.例如,您可以使用一些反三角函数从 -sin(beta)
得出Y角.给定Beta,您可以从 cos(beta)sin(alpha)
派生alpha.您也可以从 cos(beta)sin(gamma)
导出伽马.请注意,矩阵中的相同数字可以表示多个值(例如 sin(0)= 0
和 sin(180)= 0
).
现在您知道alpha,beta和gamma了,您可以反转beta并重新制作旋转矩阵.
使用四元数有一种更好的方法来完成此操作的可能性很大,但是您应该向Math StackExchange询问这类与语言无关的问题.
I have a 4x4 transformation matrix. However, after trying out the transformation I noticed that movement and rotation of the Y axis is going the opposite way. The rest is correct.
I got this matrix from some other API so probably it is the difference of coordinate system. So, how can I flip an axis of transformation matrix?
If only translation I can add minus sign on the Y translation, but I have no idea about opposite rotation of only one axis since all the rotation is being represented in the same 3x3 area. I thought there might be some way that even affect both translation and rotation at the same time. (truly flipping the axis)
Edit: I'm pretty sure the operation you're looking for is changing coordinate systems while maintaining Z-up or Y-up. In this case, try setting all the elements of the second column (or row) of your matrix to their inverse.
This question would be better for the Math StackExchange. First, a really helpful read on rotation matrices.
The first problem is the matter of rotation order. I will be assuming the XYZ rotation order. We know the rotation matrices for each axis is as follows:
Given a matrix derived from the same rotation order, the resulting matrix would be as follows, where alpha is the X angle, beta is the Y angle, and gamma is the Z angle:
You can derive the individual components of each axis angle from this matrix. For example, you can derive the Y angle from -sin(beta)
using some inverse trig. Given beta, you can derive alpha from cos(beta)sin(alpha)
. You can also derive gamma from cos(beta)sin(gamma)
. Note that the same number in the matrix can represent multiple values (e.g. sin(0)=0
and sin(180)=0
).
Now that you know alpha, beta, and gamma, you can reverse beta and remake the rotation matrix.
There's a good chance that there's a better way to do this using quaternions, but you should ask the Math StackExchange these kinds of language-agnostic questions.
这篇关于如何仅翻转变换矩阵的一个轴?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!