Question

I want to write a function to generate and store the co-ordinates of an n-cube and I have no idea how to start. Specifically, I wish to generate the co-ordinates for an evenly or randomly distributed cloud of points for this n-cube and store them. What would be a good way to start with this or if possible, a quick solution?

Was it helpful?

Solution

I don't want to give C++ source code for this problem, however, here's the thought how you could generate it.

A hypercube contains all bit-strings of length n. Thus there are 2^n possibilities for coordinates in total.

Now how you can do it recursively:

  • if you want to generate coordinates for n=1, just return 0 and 1

  • if you want to generate coordinates for n>1, take 0 and concatenate it to all possible coordinates for n'=n-1, then take 1 and concatenate it to all possible coordinates for n'=n-1

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top