title: C++ Filling an 1D array to represent a n-dimensional object based on a straight line segment
body: <p><strong>READ FIRST:</strong> I have rewritten this question with the help of a friend to be hopefully more specific in what is required. It can be found <a href="https://stackoverflow.com/questions/3004054/c-how-to-generate-the-set-of-cartesian-product-of-n-dimensional-tuples">here</a></p>
  
  <p>I'm not very clear on n-cubes, but I believe they are what I am referring to as the square family.</p>
  
  <p><strong>New Question Wording:</strong><br>
  Perhaps I wasn't clear enough. What I'm asking, is how to set a 1D array to hold data for a cloud of a number of evenly-spaced points that form the most complete representation of the space occupied by an n-cube of n dimensions. </p>
  
  <p>In 1D this would simply fill the array with a series of 1D co-ordinates creating a line segment. A 1-cube.</p>
  
  <p>In 2D however this would fill every first co-ordinate to the x value and the every second to the y, generating the most complete square possible for that spacing and number of particles. The most complete possible 2-cube.</p>
  
  <p>In 3D, this would fill ever first with x, every second with y and every third with z, generating the most complete possible cube for that spacing and number of particles. The most complete possible 3-cube.</p>
  
  <p>I wish to be able to do this for any reasonable combination of number of particles, spacing and dimensions. Ideally I could do at least up to a 4-cube using a generic fill algorithm for all n-cubes initialised to <code>double * parts_</code></p>
  
  <p>Yet another definition of what kind of object I'm trying to represent:<br>
  In 1D its a line. Sweep it through the second dimension it becomes a square. Sweep that square through the third, it becomes a cube. I presume this behaviour extends past three dimensions and wish to store a cloud of points representing the space taken up by one of these objects of any reasonable dimension, spacing and number of points in a 1D array.</p>
  
  <p><strong>The original wording of the question:</strong><br>
  I'm struggling to find a good way to put this question but here goes. I'm making a system that uses a 1D array implemented as <code>double * parts_ = new double[some_variable];</code>.  I want to use this to hold co-ordinates for a particle system that can run in various dimensions.</p>
  
  <p>What I want to be able to do is write a generic fill algorithm for filling this in n-dimensions with a common increment in all direction to a variable size. Examples will serve best I think.</p>
  
  <p>Consider the case where the number of particles stored by the array is 4</p>
  
  <p>In 1D this produces 4 elements in the array because each particle only has one co-ordinate.<br>
  1D:<br>
  <code>{0, 25, 50, 75};</code><br>
  In 2D this produces 8 elements in the array because each particle has two co-ordinates..<br>
  2D:<br>
  <code>{0, 0, 0, 25, 25, 0, 25, 25}</code><br>
  In 3D this produces 12 elements in the array because each particle now has three co-ordinates<br>
  <code>{0, 0, 0, 0, 0, 25, 0, 0, 50, ... }</code>  </p>
  
  <p>These examples are still not quite accurate, but they hopefully will suffice.</p>
  
  <p>The way I would do this normally for two dimensions:  </p>
  
  <pre><code>int i = 0; 
  for(int x = 0; x &lt; parts_size_ / dims_ / dims_ * 25; x += 25) {  
      for(int y = 0; y &lt; parts_size_ / dims_ / dims_ * 25; y += 25) { 
          parts_[i] = x;
          parts_[i+1] = y;
          i+=2;
      }
  }
  </code></pre>
  
  <p>How can I implement this for n-dimensions where 25 can be any number?</p>
  
  <p>The straight line part is because it seems to me logical that a line is a somewhat regular shape in 1D, as is a square in 2D, and a cube in 3D. It seems to me that it would follow that there would be similar shapes in this family that could be implemented for 4D and higher dimensions via a similar fill pattern. This is the shape I wish to set my array to represent.</p>
  
  <p>EDIT: Apparently I'm trying to fill this array to represent the n-cube with the fewest missing elements for the given n, spacing and number of elements. If that makes my goal any clearer.</p>