Split 3D into 1D vector

If I have a 3D cube of a given dimension, say 50x50x50, and I want to split it into smaller cubes of 5x5x5, i.e. splitting it by 10 at each edge, how can I appropriately place the smaller cubes position in the vector in such a manner that the vector index correctly represents the location of the smaller cube?

I only know of a similar example with a 2D square: if we have x=8 and y=10 square and want to divide it to 1x1, the position may be calculated as x*y + y.

I apologize if my question was unclear.
Last edited on
I think you are asking about how to address a one-dimensional array as if it was three-dimensional.
1
2
3
4
5
6
7
8
9
10
11
12
13
int main()
{
    int Height = 50, Depth = 50, Width = 50;
    int h = 10, d = 5, w = 20;

    auto a {new int[Height*Depth*Width]{}};

    a[h * (Depth * Width) + d * Width + w] = 1;
    // simplified
    a[(h * Depth + d) * Width + w] = 1;

    delete[] a;
}

Thank you very much
Topic archived. No new replies allowed.