0

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?

Ben
  • 107
  • 1
  • 12
  • And what motivates you to want to write this function? Not homework, by any chance? –  Jun 18 '10 at 15:10
  • What *do* you understand about the problem? Also, what constraints if any have been imposed on you, and what constraints may you simply opt for? For instance, you can arbitrarily decide to have the thing lined up on the coordinate system then this becomes very easy... – dmckee --- ex-moderator kitten Jun 18 '10 at 15:14
  • If this is a homework assignment, please tag it appropriately – Francesco Jun 18 '10 at 15:15
  • Possible dupe/relevant: http://stackoverflow.com/questions/3070425/c-function-calling-itself/3070637#3070637 – rubenvb Jun 18 '10 at 15:48
  • @Neil Butterworth You thought that last time too. Perhaps I might just be curious and enjoy exploring new mathematical concepts and would have an innocent motive. It is not tagged inappropriately. EDIT: Besides. What messed up teacher would set useless shit like this as homework. Generating specific solutions would be enough for nearly any application. This is my programming equivalent to a proof, a general solution. – Ben Jun 18 '10 at 15:51
  • @Ben Not since I edited the tags. However, this isn't a "maths concepts" site. –  Jun 18 '10 at 15:53
  • @Ben: Neil concern is *not* because homework questions are bad. They're fine. It is because pedagogical questions *should* get a slightly different treatment than others: they call for both a "teaching to fish" approach, and an exploration of all the options. This is quite different from a "I'm trying to get *this* done." question. *"I'm trying to learn something new, and got stuck here..."* is largely in the same boat as formal homework. – dmckee --- ex-moderator kitten Jun 18 '10 at 15:56
  • @Neil Butterworth However I would contest that this is a question on how to implement a maths concept in programming, hence the c++ tag. Specifically on a C++ data structure to store a variable size object in a convenient to access and understandable fashion, and also on how to generate the co-ordinates for this object using C++ and to fill the structure used for storing it. – Ben Jun 18 '10 at 15:57
  • @dmckee I would have enjoyed seeing a solution not simply for itself but for the prompting of further thought and exploration on why and how it was implemented that way and what other ways it may have been implemented. Even why they were discarded over the current method. I see merit in creating your own solution without seeing someone else's work too. – Ben Jun 18 '10 at 15:59
  • @Ben So that is why you have just accepted an answer that covers none of those things? –  Jun 18 '10 at 15:59

1 Answers1

2

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
  • 34,669
  • 9
  • 84
  • 115
  • 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 --- ex-moderator kitten Jun 18 '10 at 15:18
  • 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 Jun 18 '10 at 15:53