C ++ How to generate a set of Cartesian products of n-dimensional tuples

I want to generate some data that represents the coordinates of a point cloud representing an n-cube of n dimensions. These points should be evenly distributed throughout the n-space and should be generated with a user-defined spacing between them. This data will be stored in an array.

+5
source share
3 answers

I found an implementation of a Cartesian product using Boost.MPL .

There is an actual Cartesian product in Boost, but this is a preprocessor directive, I believe this is useless to you.

+2
source

, , .. . 1 , 1/n. ( , , , ).

:

for i=0;i<=n;i++   //NB i<=n because there will be n+1 points along each axis-parallel line
    for j=0;j<=n;j++
        for k=0;k<=n;k++
            addPointAt(i/n,j/n,k/n)  //float arithmetic required here

, , , , ( ) . , -, .

, , .

, , . N- 1-D . , , .

, , , ! .

+1

():

Function Hypercube(int dimensions, int current, string partialCoords)
{
  for i=0, i<=steps, i++
  {
    if(current==dimensions)
      print partialCoords + ", " + i + ")/n";
    else if current==0
      Hypercube(dimensions, current+1, "( "+i);
    else
      Hypercube(dimensions, current+1, partialCoords+", "+i);
  }

}

: Hypercube (n, 0, ""); , .

0
source

All Articles