转置矩阵 - 水平到垂直 - OpenGL ES - iPhone

发布于 2025-01-06 12:51:29 字数 268 浏览 2 评论 0原文

假设我有以下垂直矩阵:

{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}

我想对其进行翻译,以便它水平排序 - 即:

{0,4,8,12,1,5,9,13,2,6,10,14,3,7,11,15}

实现此目的最简单的方法是什么?

编辑

我已经通过手动将每个项目映射到正确的位置来完成此操作,但出于好奇想看看是否有更好的方法。

Say I have the following matrix which is vertical :

{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}

And I want to translate this so that it is ordered horizontally - i.e :

{0,4,8,12,1,5,9,13,2,6,10,14,3,7,11,15}

What would be easiest way to achieve this ?

EDIT

I have already done this by manually mapping each item to the correct position, but wanted to see if there was a better way out of curiosity.

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

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

发布评论

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

评论(1

神魇的王 2025-01-13 12:51:29

好吧,对于每个 0 <= j <我< n(当n^2是矩阵的大小时),您应该交换[i][j][j][ i] 元素。

int mat[4][4]={{0,1,2,3},{4,5,6,7},{8,9,10,11},{12,13,14,15}};
int i,j,temp;
for (i=0;i<4;i++)
 for (j=0;j<i;j++) {
  temp=mat[i][j];
  mat[i][j]=mat[j][i];
  mat[j][i]=temp;
 }

Well, for every 0 <= j < i < n (when n^2 is the size of the matrix), you should swap the [i][j] and [j][i] elements.

int mat[4][4]={{0,1,2,3},{4,5,6,7},{8,9,10,11},{12,13,14,15}};
int i,j,temp;
for (i=0;i<4;i++)
 for (j=0;j<i;j++) {
  temp=mat[i][j];
  mat[i][j]=mat[j][i];
  mat[j][i]=temp;
 }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文