views:

53

answers:

1

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?

+2  A: 

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

phimuemue
Correct if the n-cube's axis line up with the basis of the coordinate system. Allowing for rotations in a Cartesian n-space is a bit harder. Allowing for a non-Cartesian space is rather a lot more complicated.
dmckee
@phimuemue Thanks. You answered my other question too. This answers the comment there also that this kind of generation necessitates exponential runtime with increasing dimensions. Time to do some maths study. I'll be back if I get stuck on something specific.
Ben