我需要从1D阵列中提取4D位置.我可以看到2D和3D是怎么回事,但是我很难将头围绕在第四维度上.
对于2D:
int* array = new int[width * height];
int index = y * width + x;
int x = index / height
int y = index - x * height;
Run Code Online (Sandbox Code Playgroud)
对于3D:
int* array = new int[width * height * depth];
int index = z * width * height + y * width + z;
int x = index / (height * depth);
int y = index - (x * height * depth) / depth;
int z = index - …Run Code Online (Sandbox Code Playgroud)