将2D转换的1D阵列顺时针旋转90度
Rotating a 2D converted 1D array 90 degrees clockwise
这几天我一直在纠结,我快要疯了。本质上,我已经将值的2D阵列(图像,我知道有更简单的方法可以实现这一点,但我有明确的要求)转换为1D阵列。我可以轻松地旋转2D阵列。我在旋转1D版本的数组时遇到了问题,我认为这是因为一行算法不正确。我用来旋转阵列的代码是:
cout << "nTransfer from 2D to dynamic 1D array and print detailsnn";
myImage * p_myImage = new myImage[total];
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
int offset = width * y + x;
p_myImage[offset].pixel = array2D[y][x];
cout << p_myImage[offset].pixel << " ";
}
cout << "n";
}
//new pointer to copy to
myImage * p_myImage2 = new myImage[total];
cout << "nRotate Matrix through 1D arraynn";
for (int x = 0; x < width; x++)
{
for (int y = 0; y < height; y++)
{
int offset = height * x + y;
//int offset = width * y + x ;
p_myImage2[offset].pixel = p_myImage[height-1+x].pixel;
cout << p_myImage2[offset].pixel << " ";
}
cout << "n";
}
这应该顺时针旋转:
p_myImage2[offset].pixel = p_myImage[width * (height - 1 - y) + x].pixel;
相关文章:
- 与互斥锁相比,旋转锁可以保证上下文切换
- 绘制顺时针三角形,重新排序点
- 顺时针迭代旋转 3 位数字
- 顺时针旋转 M*N 矩阵 90 度,C++
- 简化代码以避免在顺时针旋转2D矩阵时出现TLE
- C ++试图理解用于破译复杂语法的顺时针规则
- 如何顺时针旋转PGM文件
- 顺时针旋转90度图像
- 顺时针旋转2D阵列
- 将2D转换的1D阵列顺时针旋转90度
- 顺时针递增我的球面坐标
- 在OpenGL中顺时针和逆时针
- 如何顺时针交换二次矩阵的四分之一(从左上角开始)
- 从中心按顺时针展开螺旋线打印二维阵列
- 顺时针和逆时针旋转阵列的有效方式
- 旋转NxN矩阵计数器(反)-顺时针90度
- 由数字围绕矩形按顺时针方向移动组成的图案(长度和宽度每次递减)
- 如何在c++中制作数字顺时针旋转的二维数组
- 这个代码是逆时针还是顺时针旋转关于叉积的点云
- 直接计算两个向量之间顺时针角度的方法