如何从旋转矩阵中删除轴?

发布于 2024-11-02 09:05:53 字数 76 浏览 0 评论 0原文

我有一个 opengl 任意旋转矩阵,想删除 X & Y 轴,只剩下 Z 轴?

这可能吗?有关如何做的任何指示吗?

I have an opengl arbitrary rotation matrix and would like to remove the X & Y axis, leaving me with only the Z axis?

Is this possible? Any pointers on how to do it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一曲爱恨情仇 2024-11-09 09:05:53

只是在这里大声思考,但是你不能使用矩阵来旋转像 (1,0,0) 这样的向量,然后执行 atan2(y,x) 看看它旋转了多少,然后构建一个新的矩阵来旋转Z轴差那么多?

Just thinking out loud here, but can't you use the matrix to rotate a vector like (1,0,0), then do atan2(y,x) to see how much it's rotated and then build a new matrix to rotate through the Z axis by that much?

瀟灑尐姊 2024-11-09 09:05:53

在仅围绕 z 轴的旋转中,z 轴应保持不变。所以上面的建议有点与你想要的相反。

假设您有一个任意 OpenGL 矩阵:

    | r_xx r_xy r_xz t_x |
    | r_yx r_yy r_yz t_y |
M = | r_zx r_zy r_zz t_z |
    |  0    0    0    1  |

其中 t_i 元素是平移,r_jk 元素是旋转分量。您想要一个如下所示的矩阵:

| cos(th) sin(th)  0  t_x |
|-sin(th) cos(th)  0  t_y |
|  0       0       1  t_z |
|  0       0       0   1  |

除非矩阵具有缩放因子或接近奇点,否则您应该能够通过将矩阵的 z 部分归零然后重新标准化列来获得此矩阵。由于 OpenGL 矩阵是列主序:

double xLen = sqrt(M[0]*M[0] + M[1]*M[1]); // Singularity if either of these
double yLen = sqrt(M[4]*M[4] + M[5]*M[5]); //  is equal to zero.

M[0]/=xLen; M[1]/=xLen; M[2]=0; // Set the x column
M[4]/=yLen; M[5]/=yLen; M[6]=0; // Set the y column
M[8]=0; M[9]=0; M[10]=1;        // Set the z column
//Don't change the translation column

In a rotation that is only around the z-axis, the z axis should remain unchanged. So the above recommendation is sort of the reverse of what you want.

Let's assume you have an arbitrary OpenGL matrix:

    | r_xx r_xy r_xz t_x |
    | r_yx r_yy r_yz t_y |
M = | r_zx r_zy r_zz t_z |
    |  0    0    0    1  |

Where the t_i elements are translations and the r_jk elements are components of rotation. You want a matrix that looks like this:

| cos(th) sin(th)  0  t_x |
|-sin(th) cos(th)  0  t_y |
|  0       0       1  t_z |
|  0       0       0   1  |

Unless the matrix has scaling factors or is close to a singularity, you should be able to get this by just zeroing out the z parts of the matrix and then re-normalizing the columns. Since an OpenGL matrix is column major order:

double xLen = sqrt(M[0]*M[0] + M[1]*M[1]); // Singularity if either of these
double yLen = sqrt(M[4]*M[4] + M[5]*M[5]); //  is equal to zero.

M[0]/=xLen; M[1]/=xLen; M[2]=0; // Set the x column
M[4]/=yLen; M[5]/=yLen; M[6]=0; // Set the y column
M[8]=0; M[9]=0; M[10]=1;        // Set the z column
//Don't change the translation column
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文