title: 4D position from 1D index?
body: <p>I need to extract a 4D position from a 1D array. I can see how it goes for 2D and 3D but I'm having a hard time wrapping my head around the 4th dimension..</p>
  
  <p>For 2D:</p>
  
  <pre><code>int* array = new int[width * height];
  int index = y * width + x;
  int x = index / height
  int y = index - x * height;
  </code></pre>
  
  <p>For 3D:</p>
  
  <pre><code>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);
  </code></pre>
  
  <p>For 4D ?</p>
  
  <pre><code>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 = ??
  </code></pre>