title: 1D vector - 3D indices
body: <p>I am using a 1D vector to represent a 3D data structure, with indices 0 to x*y*z, where x, y and z are the number of cells in each direction.</p>
  
  <p>In order to index a specific cell [xi][yi][zi], I use:</p>
  
  <pre><code>index = xi + x*yi + x*y*zi ;
  </code></pre>
  
  <p>My problem is, I can't work out how to go the other way!</p>
  
  <p>e.g. I want to get the individual coordinates represented in index 43.</p>
  
  <p>I think I've worked out how to get xi:</p>
  
  <pre><code>xi = index % x ;
  </code></pre>
  
  <p>but I can't for the life of me get the others... :/</p>
  
  <p>EDIT: Hmmm. Is this right?</p>
  
  <pre><code>xi = index % x;
  yi = ((index - xi)/x) % y;
  zi = ((index - xi - x*yi) / x) / y ;
  </code></pre>