title: How do I convert a 1d index into a 3d index?
body: <p>I looked at this question: <a href="https://stackoverflow.com/questions/11316490/convert-a-1d-array-index-to-a-3d-array-index">Convert a 1d array index to a 3d array index?</a> but my result differs when I test it no matter how I calculate the index in the first place.</p>
  
  <p>I am using the following to convert 3d (x,y,z) in dimensions (WIDTH, HEIGHT, DEPTH) to 1d:</p>
  
  <pre><code>i=x+WIDTH(y+HEIGHT*z)
  </code></pre>
  
  <p>Then to convert back from index i to (x,y,z):</p>
  
  <pre><code>z=i/(HEIGHT*WIDTH)
  y=(i/WIDTH)%HEIGHT
  x=i%(WIDTH)
  </code></pre>
  
  <p>When I test this between both methods I get the wrong results. Is there something obviously wrong with my method? What is the correct explanation?</p>