Draw a hypercube of order N in a 3D environment

36 Views Asked by At

I must first state that this question involves a little bit of programming, but is mostly a mathematical question.

I am trying to draw a hypercube graph in 3D. Up to dimension 3 everything is easy. The problem arises when I enter higher dimensions. I have came up with a simple algorithm to translate the binary string that corresponds to a vertex to a 3D coordinate.

The algorithm is fairly simple:
Let's assume our binary string has 5 binary digits: 011 01
this means, that I should offset the vertex by:
$0*0+0*0$ in $x$ direction
$1*1+{1 \over 2} * 1$ in $y$ direction
$1*1$ in $z$ direction
So I take the first three binary digits, each one of them tells me if I should move the vertex in the corresponding direction. I then take the three remaining digits, they also tell me how to move the vertex, but this time the distance moved is halved, and so on.

I have not yet tried to connect the vertices with lines but as You can see some lines would overlap with my current method and would be indistinguishable.
Here is an example of $Q_3$:
$Q_3$ screenshot
And $Q_4$, You can already notice some lines would overlap if I had connected the vertices:
$Q_4$ screenshot

Now I think that the implementation Isn't important, but for completeness sake I will provide it as well:

float Node::get(unsigned bpos){
    float cnt = 0;
    float sum = 0;
    unsigned i;
    for(i = bpos; i < binaryRep.size(); i+=3){
        if(binaryRep.at(i) == true)
            sum += 1.0/((i/3)+1.0f);
        cnt += 1/((i/3)+1.0f);
    }
    if(cnt == 0) return 0;
    sum -= cnt/2;
    sum /= cnt;
    return sum;
}

If I want to get the X displacement I will call get(0), for Y It's get(1) etc. binaryRep is an array-like structure that contains the binary string corresponding to the vertex, and It's size method returns the length of the binary string.

So that is all I have managed to come up with. Is there a way to represent those graphs in a 3D environment such that the lines will not overlap? Some better way of translating the binary string to 3D coordinates?