如何将3D矩阵逆时针旋转90度? [英] How do I rotate a 3D matrix by 90 degrees counterclockwise?
本文介绍了如何将3D矩阵逆时针旋转90度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Java中,我试图将矩阵逆时针旋转90度.我找到了有关如何使用2D矩阵执行此操作的答案,但我的矩阵是3D.
I'm trying to rotate a matrix counterclockwise by 90 degrees in Java. I found answers on how to do this with a 2D matrix, but my matrix is 3D.
这是我发现如何进行2D旋转的方法:
Here's how I found out on how to do a 2D rotation:
static int[][] rotateCW(int[][] mat) {
final int M = mat.length;
final int N = mat[0].length;
int[][] ret = new int[N][M];
for (int r = 0; r < M; r++) {
for (int c = 0; c < N; c++) {
ret[c][M-1-r] = mat[r][c];
}
}
return ret;
}
那我该如何旋转3D矩阵?
How would I go about rotating a 3D matrix then?
推荐答案
通过将矩阵乘以旋转矩阵
x轴的基本矩阵是:
| 1 0 0 |
Rx(a) = | 0 cos(a) -sin(a) |
| 0 sin(a) cos(a) |
对于90度,只需将cos(90)= 0和sin(90)= 1设置为:
For 90 degrees simply set cos(90) = 0 and sin(90) = 1 which should lead to:
| 1 0 0 |
Rx(a) = | 0 0 -1 |
| 0 1 0 |
这篇关于如何将3D矩阵逆时针旋转90度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文