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 return0
and1
if you want to generate coordinates for
n>1
, take0
and concatenate it to all possible coordinates forn'=n-1
, then take1
and concatenate it to all possible coordinates forn'=n-1
phimuemue
2010-06-18 15:13:02
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
2010-06-18 15:18:52
@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
2010-06-18 15:53:30