Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Geek Culture / Algorithm for creating an n dimensional hypercube.

Author
Message
Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 10th Dec 2009 00:54
Well, i was bored in math class today...



I'm working on creating a 4D object viewer, and i figured i'd start out with a standard 4 dimensional "cube". It's easy enough to come up with all of the points for it, but another problem is what points to connect the other points to (by drawing a line). So, i started working my way up from 1 dimension to 3 dimensions, and it seemed apparent that there's a pattern. I decided to make an algorithm for generating an n dimensional hypercube, width 2.

n is the number of dimensions of the hypercube.
Each point P is connected to n other lines.
There are 2^n points in the hypercube

Start out with a zeroed binary number, n digits long.
IE
n n-1 ..... 2 1 <- dimension
0 0 ..... 0 0 <- digit
This number is L
For each point P, increase L by 1, and use this number as an ID (identifier) for point P, starting from ID 0.
The locations of each point on each axis
IE
n n-1 ...... w z y x

is -1 if the corresponding binary digit is 0, and 1 if the corresponding binary digit is 1.

EX:
n=4
ID=5 (0101 base 2)

0 1 0 1 <- corresponding binary digit
w y z x <- dimension
-1 1 -1 1 <- location on the corresponding axis.

In programmer\\\'s words, where a is the ID, and b is the dimension number (from 0 to n-1):
location=-1*(-1)^((a>>b)&1);


Now you have the location of each point P, but you still need to find out which other points, from any point P, to draw lines to.

For every digit of every point P that is 0, that point hooks up to ID+2^digit. This will give you n points on the first ID number (00...00) and 0 points on the last (11...11).

In programmer talk, where a and b are as described above, and \\\"hook\\\" is a variable storing an ID that point a hooks up to:
if(((a>>b)&1)==0)
{
hook=a+2^b;
P[a].hook=hook;
P[hook].hook=a;//*
}
The line with the asterisk makes sure that every point has n points it hooks up to, otherwise P[hook] would remain empty.

And there you have it! Easy, right?

Here are the results i got for dimensions 1-5. Notice how for the \\\"Hooks\\\", each number only occurs N times.

n=1 (line)

^^little glitch when n=1 with the text output

n=2 (square)


n=3 (cube)


n=4 (hypercube)


n=5 (UBERcube!!!!!)


I tried to post this with an example of a ten dimensional cube, but it was 1024 lines, and i think it broke the internet...

Jeff032
17
Years of Service
User Offline
Joined: 13th Aug 2007
Location:
Posted: 10th Dec 2009 02:05
Cool.

Could it not be more simply stated as this?

If dimension = n
Points = every possible set of length n from {-1, 1}
Hooks(p) = all points that share exactly n-1 elements with p



Though I guess that won't generate then as fast as your method does.

Would you mind sharing the code for that?

-Jeff

Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 10th Dec 2009 03:08
Quote: "If dimension = n
Points = every possible set of length n from {-1, 1}
Hooks(p) = all points that share exactly n-1 elements with p"

Yeah, but then you'd have to loop through everything a couple times and... meh. Those statements are actually exactly what i based my algorithm off of When i drew it out, i found that a pattern emerged, like this:

000 - 001 010 - 011 100 - 101 110 - 111

where a - denotes that the points connect. I realized that if their positions were based off their ID, everything where the only change is a 1 to a 0 or a 0 to 1, can be identified by an ID.

Here's t3h codez

I'm still learning java, so CnC on any weird coding is welcome!

Peter H
21
Years of Service
User Offline
Joined: 20th Feb 2004
Location: Witness Protection Program
Posted: 10th Dec 2009 04:15 Edited at: 10th Dec 2009 04:17
Regardless of what mathematicians try to tell you. We only have 3 spatial dimensions. You can make all the theoretical dimensions you want, but the irony is that you're still representing them inside a 3-dimensional space (and many times, such as in this case, a 2-dimensional representation of that 3-dimensional space).

edit: this is speaking as a person who has taken every single (challenging) math class at my university, and has been begged to switch to a mathematics degree(which i will not do).

One man, one lawnmower, plenty of angry groundhogs.
Xarshi
19
Years of Service
User Offline
Joined: 25th Dec 2005
Location: Ohio
Posted: 10th Dec 2009 05:32
Quote: "Regardless of what mathematicians try to tell you. We only have 3 spatial dimensions. You can make all the theoretical dimensions you want, but the irony is that you're still representing them inside a 3-dimensional space (and many times, such as in this case, a 2-dimensional representation of that 3-dimensional space).

edit: this is speaking as a person who has taken every single (challenging) math class at my university, and has been begged to switch to a mathematics degree(which i will not do)."

We only see in three dimensions. We can easily derive the other spatial dimensions mathematically. You won't be able to comprehend them, but we can perform calculations with them.

Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 10th Dec 2009 05:40 Edited at: 10th Dec 2009 06:05
This is purely theoretical - i'm just doing it for fun, because multi-dimensional stuff is cool. Also, because i just made a 3d rotating box, and i want to expand this to make sure i have the concept down. I might even try to make a n-dimensional model viewer as well.

However you do make a good point. The bending of space (theory of relativity) still just modifies our three spatial dimensions, along with those other unconfirmed dimensions (What's dimensions are involved in string theory? Dimensions 5-11?)

Also, just out of curiosity, what do you major in currently, if not mathematics?


[edit]
Quote: "We only see in three dimensions. We can easily derive the other spatial dimensions mathematically. You won't be able to comprehend them, but we can perform calculations with them."

We can easily create theoretical models of other dimensions, but not the ones that actually apply to the real world. There is also no law or rule that says we can't comprehend multiple (theoretical) dimensions. It would just be very hard (because we're so used to 3 dimensions), and extremely impractical.

Peter H
21
Years of Service
User Offline
Joined: 20th Feb 2004
Location: Witness Protection Program
Posted: 10th Dec 2009 11:01 Edited at: 10th Dec 2009 11:20
Quote: "Also, just out of curiosity, what do you major in currently, if not mathematics?"

I'm double majoring in Mechanical Engineering and Materials Joining Engineering. (I would actually have a B.S. in mathematics right now if i took all the filler courses and electives required by my university. But it would probably add a year to my already long schedule, and i wouldn't learn much, just have what i already know recognized by some paper, which is useless if i'm not going into that field for a job/career )

Quote: "along with those other unconfirmed dimensions (What's dimensions are involved in string theory? Dimensions 5-11?)"

That's just the thing unfortunately, they are all unconfirmed and theoretical (string theory)

Creating mathematical models of more than 3 dimensions is certainly fun, and it can be useful, but don't assume that there are more than 3 spatial dimensions. What i'm saying is that matter as we know for sure right now, exists in three dimensions.

Sure there are plenty of theories such as string theory, and viewing space as a fabric that gravity effects, that involve more than 3 dimensions, but they are still only theories and have not been proven.

Again, i don't want to rain on your parade, this is all fun and useful! It's just a pet peeve of mine when people consider it as a fact.

Quote: "This is purely theoretical - i'm just doing it for fun, because multi-dimensional stuff is cool. Also, because i just made a 3d rotating box, and i want to expand this to make sure i have the concept down. I might even try to make a n-dimensional model viewer as well."

As i can see, you already understand, so i'm just venting against other people i've met that aren't even here now

One man, one lawnmower, plenty of angry groundhogs.
Diggsey
19
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 10th Dec 2009 18:35
@Peter H
Our eyes only see in 2D anyway, it is our brain which overlays the two images to create a 3D effect. So giving our eyes a 4D image projected onto 2D doesn't seem that different from a 3D image onto 2D.

Peter H
21
Years of Service
User Offline
Joined: 20th Feb 2004
Location: Witness Protection Program
Posted: 11th Dec 2009 02:37
Quote: "Our eyes only see in 2D anyway, it is our brain which overlays the two images to create a 3D effect. So giving our eyes a 4D image projected onto 2D doesn't seem that different from a 3D image onto 2D."

Good point. Except that a 3D effect is a representation of reality, while a 4D effect is currently fantasy.

One man, one lawnmower, plenty of angry groundhogs.
Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 11th Dec 2009 07:58
Quote: "while a 4D effect is currently fantasy."

theory of relativity. bending of space time around an object of mass or (most noticeably) a black hole.

Although I guess I can't really argue for or against it, seeing as how i have no clue about the math behind it...

Peter H
21
Years of Service
User Offline
Joined: 20th Feb 2004
Location: Witness Protection Program
Posted: 11th Dec 2009 10:31
I think our definitions are different hence all the confusion. The theory of relativity still only uses three spatial dimensions (which are then bent, along with time, etc, etc). So the theory of relativity simply manipulates those three dimensions, along with time, in different ways.

I think we're saying the same thing, just with different words...

One man, one lawnmower, plenty of angry groundhogs.
Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 14th Dec 2009 07:43
Just some more properties of the hypercube:

Each point is sqrt(n) units away from the origin.
Each point's hooks are at 90 degree angles to each other.
The distance between any point and any one of it's hooks is 2.
where d is the distance between any two points, 2<=d<=2*sqrt(n)

Also, i haven't done any mathematical proofs of this, but i believe that if you flip each bit of a point's ID (binary not) you get the point that is furthest from it. IE:
ID: 0110101
furthest point @
ID: 1001010

Chris K
21
Years of Service
User Offline
Joined: 7th Oct 2003
Location: Lake Hylia
Posted: 14th Dec 2009 17:31
Quote: "Regardless of what mathematicians try to tell you. We only have 3 spatial dimensions."


I don't think a mathematician would ever try to tell you anything about the world...

-= Out here in the fields, I fight for my meals =-
Zotoaster
20
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 14th Dec 2009 18:10
Peter H, the thing is that maths all holds together until you get to 11 dimensions.

Imagine this: you want to represent the position of something. You can do that using the vector (x, y, z). Now, I tell you that I walk from point A(0, 0, 0) to point B(5, 0, 0) over a space of 5 seconds, meanwhile, my lamp is always at point (3, 4, 5).

If I ask you, where am I when my lamp is at point (3, 4, 5), well, you would say I'm anywhere between A and B, right? You need another piece of information to make sure. That is the extra dimension in our vector, time.

So, now I tell you that I walk from (0, 0, 0, 0) to (5, 0, 0, 5) in the coordinate system (x, y, z, t) (where t is time). Now I ask you, where am I when my lamp is at (3, 4, 5, 2). Well, I am probably going to be at (2, 0, 0, 2), right?



Mathematically, you need this extra dimension. In the common sense world, you need it just as much. We may only see in 3D, but there is a need for the 4th dimension to be there (and in fact, all of Einstein's theories are based on this fact.. and they are proven).

"everyone forgets a semi-colon sometimes." - Phaelax
Diggsey
19
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 14th Dec 2009 18:47
@Zotoaster
That doesn't make time a spatial dimension though. Time IS a dimension, but it's a temporal dimension.

Zotoaster
20
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 14th Dec 2009 19:32
Is up a spatial dimension to a flatlander? Not really, but what we call time, they could just as well call up, because although in 3D we can see all their times (or ups) at the same moment, they experience it one cross-section at a time.

We experience time one cross-section at a time, but if you were in 4D-land, it would be a spatial dimension, and you could see an object as it was in the past and as it will be in the future, all in the same "time".

"everyone forgets a semi-colon sometimes." - Phaelax
Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 15th Dec 2009 01:46 Edited at: 15th Dec 2009 01:50
Let me just point out that you don't have concrete evidence for that, zotoaster, and so your statements are not in the least bit proven (in this thread).

Quote: "Mathematically, you need this extra dimension. In the common sense world, you need it just as much. We may only see in 3D, but there is a need for the 4th dimension to be there (and in fact, all of Einstein's theories are based on this fact.. and they are proven)."


I don't think that anyone is arguing about the "existence" of other dimensions, just that we only have three spatial dimensions, which is true (we can't project our view into this fourth dimension, rotate it, or get off of our hyperplane of time, the latter being the most important).

Still, I really want to emphasize that without knowing everything behind Einstein's work, and all the math involved behind the proposed 11 dimensions, we aren't really qualified to say anything about multiple dimensions in relation to the real world for certain.

[edit]

yknow, i just thought of something that would be really cool! imagine a 2d game, where you could move shapes around (or something similar), and then view that with the z dimension being time (so a circle moving around would look like a winding snake in 3d view). That's not all that exciting, but wouldn't it be cool to expand that to four dimensions? Move a sphere around, and then see the 4 dimensional projection of that sphere with the w axis being time? Yeah, that'd be cool!

Zotoaster
20
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 15th Dec 2009 01:52
Quote: "r get off of our hyperplane of time, the latter being the most important"


IIRC, that's the 6th dimension, right?

"everyone forgets a semi-colon sometimes." - Phaelax
commodore 01000000
15
Years of Service
User Offline
Joined: 14th Dec 2009
Location:
Posted: 15th Dec 2009 11:44
4D shape?
Isn't the 4th dimension time?

Merry Xmas everyone ^^

Login to post a reply

Server time is: 2025-06-06 22:39:16
Your offset time is: 2025-06-06 22:39:16