2
我需要從1D數組中提取4D位置。我可以看到它是如何去爲2D和3D的,但我有一個很難包裝我周圍的第四維頭..一維索引的4D位置?
對於2D:
int* array = new int[width * height];
int index = y * width + x;
int x = index/height
int y = index - x * height;
對於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 - (x * height * depth) - (y * depth);
對於4D?
int* array = new int[width * height * depth * duration];
int index = w * width * height * depth + z * width * height + y * width + w;
int x = index/(height * depth * duration);
int y = ??