Hypercubes
(or N-dimensional cubes)

By Jonathan Bowen (October 1981)


An introduction to the fourth dimension

Man has been fascinated about the possibility of there being more than three dimensions ever since he has understood the concept. Henry More (1614-1687) considered that spirits have four dimensions. H.G. Wells suggested that the fourth dimension is time in The Time Machine. This can be misleading in fact since time is somewhat different from the other three dimensions as we know them. Abbott's Flatland (1) is probably nearer the mark. He considers the life of a 2-dimensional square which suddenly has the chance to travel in three dimensions. This gives the square the ability to see inside objects in its 2-dimensional world, something it previously thought was impossible. Using this analogy from three to four dimensions, we would be able to see inside solid objects if we were able to break out of our own 3-dimensional world into the fourth dimension. Taking the analogy further, when a 3-dimensional object crosses a 2-dimensional world its inhabitants simply see an object appear from nowhere, grow in size, changing its shape in a rather odd manner if the object is irregular, and then decrease in size until it disappears again. In our world this would be the equivalent of an object suddenly appearing somewhere, growing in size, shrinking and then disappearing without trace. This may soung very disturbing but this is because we do not fully understand the fourth dimension.

Projecting N-dimensional objects

What is a dimension? We may define a dimension as being a direction which is at right angles to any other dimension. In our world we simply run out of directions after we have defined three dimensions (length, width and height for example). However there is no reason why there should be anything special about three dimensions apart from the fact that we live in a 3-dimensional world. Thinking in terms of three dimensions is simply of the most practical use to us. We are quite willing to project 3-dimensional objects into two dimensions when we draw or photograph them. Again this because it is useful to us (e.g. an architect's plan of a house). There is no reason why we may not project objects of more than three dimensions. Note that in this case we also have the choice of projecting them into three dimensions if we wish. Probably the simplest and most interesting objects to consider for projection are polytopes. These are geometrical figures bounded by portions of lines, planes or hyperplanes (for polytopes of 2, 3 and 4 or more dimensions respectively). In two dimensions the polytope is known as a polygon and in three dimensions it is known as a polyhedron. For simplicity we shall restrict ourselves to regular polytopes in which all the vertices, edges, faces, etc. are the same. In two dimensions these consist of the equilateral triangle, square, etc. There are an infinite number of these. In three dimensions there are only five such solids known as the Platonic polyhedra which were discovered by the ancient Greeks. These are the tetrahedron, cube, octahedron, dodecahedron and icosahedron. A complete description of these and many other polyhedra may be found in Mathematical Models by Cundy and Rollett (2). In four dimensions there are six such polytopes, five of which may be considered as the four dimensional equivalents of the Platonic polyhedra. These are described in Coxeter's Regular Polytopes (3). In fact it turns out that the tetrahedron, cube and octahedron have similar equivalents in any number of dimensions. A simple algorithm may be used to generate the polytope for the next dimension up in each case (3). These may be projected in two dimensions. The cube was chosen out of the other two possiblities since this produces more interesting projections having square rather than triangular sides. However the reader may be interested in investigating the other two himself. For those interested in more complicated polytopes, Coxeter's Regular Complex Polytopes (4) is recommended.

Generating an N-dimensional cube

A cube of N dimensions may be generated from a cube of (N-1) dimensions in the following manner. Take the (N-1)-dimensional cube and redraw it displaced along a new dimension by a distance equal to the length of one of its sides. Now join the corresponding vertices of each of the old cubes and the new cube is formed. This may be demonstrated by starting with a "cube" of zero dimensions. This consists of a single point as would any 0-dimensional object. Displace this point along any dimension by a given distance (say a distance L from the origin along the X-axis - see figure 1.1). We now have a line of length L (a 1-dimensional cube). Next displace this line a distance L along a new dimension (say the Y-axis) and join the corresponding ends (see figure 1.2). We have now formed a square, a 2-dimensional cube. Now along the Z-axis, join the corresponding corners and we form the standard 3-dimensional cube (see figure 1.3). If we displace the cube along a new axis (say the W-axis) and join the corresponding vertices we form what is generally known as a hyper-cube or 4-dimensional cube (see figure 1.4). We may now continue this process as many times as we wish to form a multi-dimensional cube of any given number of dimensions.

A program to draw N-dimensional cubes

The program listed in figure 2 draws N-dimensional cubes. It was written to run on a Research Machines 380Z microcomputer with high resolution graphics but could be adapted to run on any computer with BASIC and a line plotting facility of some sort. The number of dimensions that can be plotted is limited by the resolution of the plotting device. Above about 8 dimensions the cube becomes too complex to be viewed on the Research Machines screen. Other systems may be able to plot more or less dimensions than this. Below 3 dimensions the "cube" is no longer a true cube. The program draws the cubes symmetrically so that above about 4 dimensions some very pretty and interesting patterns are produced (see figures 3.1 to 3.7).

How the program works

First the desired number of dimensions is read into the variable N in line 170. Lines 260 to 400 initialise the arrays X1 and Y1. These contain the coordinate offsets necessary to plot each possible direction of the cube's sides. Lines 410 to 520 calculate the origin coordinates (X0,Y0) and the size factor (F). Line 530 positions the origin. The FOR loop from lines 540 to 830 calculates the start and finish positions of each edge of the cube and draws a line between them. Arrays I1 and I2 contain flags (with values of 0 or 1) which are used to indicate which coordinate offsets are to be used for the beginning and end coordinates of each edge plotted. Lines 610 to 660 calculate the starting position and line 670 positions the current coordinates at that position. Lines 680 to 730 calculate the end position and line 740 draws a line to that position. Finally the program loops back to line 90, displays the number of dimensions of the cube (line 140) and prompts the user for a new value of N. The program may then be rerun if desired or terminated by typing a carriage return on a blank line.

Converting the program to other systems

The following lines contain special calls and commands to control graphics on the Research Machines 380Z and will need to be changed for other systems:

References <--- Updated" WIDTH=80 HEIGHT=20>

  1. gopher://wiretap.spies.com/00//Library/Classic/flatland.txtFlatland, E.A. Abbott (6th ed., Blackwell 1950)
  2. http://www.amazon.com/exec/obidos/ISBN=0198325045Mathematical Models, H.M. Cundy & A.P. Rollett (2nd ed., O.U.P. 1961)
  3. http://www.amazon.com/exec/obidos/ISBN=0486614808Regular Polytopes, H.S.M. Coxeter (2nd ed., Macmillan 1963)
  4. http://www.amazon.com/exec/obidos/ISBN=0521394902Regular Complex Polytopes, H.S.M. Coxeter (C.U.P. 1974)

List of figures

Figure 1.1
Generation of a 1-dimensional cube (a line)
Figure 1.2
Generation of a 2-dimensional cube (a square)
Figure 1.3
Generation of a 3-dimensional cube (a normal cube)
Figure 1.4
Generation of a 4-dimensional cube (a hyper-cube)
Figure 2
Program Listing
Figure 3.1
Plot of a 3-dimensional cube
Figure 3.2
Plot of a 4-dimensional cube
Figure 3.3
Plot of a 5-dimensional cube
Figure 3.4
Plot of a 6-dimensional cube
Figure 3.5
Plot of a 7-dimensional cube
Figure 3.6
Plot of a 8-dimensional cube
Figure 3.7
Plot of a 9-dimensional cube
Figure 3.8
Plot of a 10-dimensional cube
Figure 3.9
Plot of a 11-dimensional cube
Figure 3.10
Plot of a 12-dimensional cube
Figure 3.11
Plot of a 13-dimensional cube
Figure 3.12
Plot of a 14-dimensional cube
Figure 3.13
Plot of a 15-dimensional cube

Acknowledgement: The above plots were generated using a Java program which is accessible on-line, written by Andy Wallace.


Figure 1.1

                                Z 
                         W      . 
                          .     . 
                           .    . 
                            .   . 
                             .  . 
                              . . 
                               .. 
                                .__________. . . . X
                               .
                              . 
                             .
                            . 
                           .
                          . 
                         Y

Figure 1.2

                                Z 
                         W      . 
                          .     . 
                           .    . 
                            .   . 
                             .  . 
                              . . 
                               .. 
                                .__________. . . . X
                               /          / 
                              /          /
                             /          / 
                            /__________/
                           .
                          . 
                         Y

Figure 1.3

                                Z 
                        W       . 
                         .      . 
                          .     .__________ 
                           .   /|         /|
                            . / |        / |
                             /  |       /  |
                            /__________/   |
                            |  .|      |   |
                            |   |______|___| . . . X
                            |  /       |  / 
                            | /        | /
                            |/         |/ 
                            |__________|
                           .
                          . 
                         Y

Figure 1.4

                                Z 
                                . 
                    W           . 
                     .     __________ 
                      .  /|\    .   /|\ 
                       ./ | \   .  / | \
                       /. |  \  . /  |  \ 
                      /__________/   |   \
                      |\  |    \_|\_______\ 
                      | \ |____/||_\_|    /|
                      |  \/\  / ||  \ \  / |
                      |  /\ \/  || / \ \/  |
                      | /  \/_________\/\  |
                      |/____|___||     | \ |
                       \    |  \|_\____|__\| . . . X
                        \   |  /   \   |  / 
                         \  | /     \  | /
                          \ |/       \ |/ 
                           \|_________\|
                           .
                          . 
                         Y

Figure 2

 10 REM N-dimensional  cube  program   to
 20 REM run  on  Research  Machines  380Z
 30 REM with  high  resolution  graphics.
 40 REM Written   by    Jonathan   Bowen,
 50 REM Imperial College, London SW7 2AZ.
 60 REM Date 22-Oct-81
 70 REM COPYRIGHT (C) 1981 J.P.BOWEN
 80 DIM X1(10),Y1(10),I1(10),I2(10)
 90 GRAPH 1
 100 PRINT
 110 IF N>0 THEN 140
 120 PRINT "N-dimensional cube program"
 130 GOTO 150
 140 PRINT TAB(8);N;"dimensional cube"
 150 PRINT
 160 PRINT
 170 INPUT "Enter no of dimensions (2-10)";N
 180 CALL "RESOLUTION",0,1
 190 IF N>1 THEN 250
 200 PRINT
 210 PRINT
 220 PRINT "End of cube program"
 230 GRAPH 0
 240 END
 250 IF N>10 THEN 170
 260 P=3.14159/N
 270 I=-1
 280 FOR J=1 TO N STEP 2
 290  I=I+1
 300  C=I*P
 310  X1(J)=COS(C)
 320  Y1(J)=SIN(C)
 330 NEXT J
 340 I=N
 350 FOR J=2 TO N STEP 2
 360  I=I-1
 370  C=I*P
 380  X1(J)=COS(C)
 390  Y1(J)=SIN(C)
 400 NEXT J
 410 F=0
 420 FOR J=1 TO N
 430  F=F+Y1(J)
 440 NEXT J
 450 X0=0
 460 FOR J=1 TO N
 470  IF X1(J)<0 THEN http://www.cs.reading.ac.uk/people/jpb/publications/ndcubes.html#Line-X0=X0+X1(J)
 480  I1(J)=0
 490 NEXT J
 500 F=190/F
 510 X0=X0-40/F
 520 Y0=0
 530 CALL "OFFSET",X0*F,Y0*F
 540 FOR I=1 TO 2^N-1
 550  FOR J=1 TO N
 560   I2(J)=I1(J)
 570  NEXT J
 580  FOR J=1 TO N
 590   IF I1(J)=1 THEN 760
 600   I2(J)=1
 610   X=0
 620   Y=0
 630   FOR K=1 TO N
 640    X=X+I1(K)*X1(K)
 650    Y=Y+I1(K)*Y1(K)
 660   NEXT K
 670   CALL "PLOT",X*F,Y*F
 680   X=0
 690   Y=0
 700   FOR K=1 TO N
 710    X=X+I2(K)*X1(K)
 720    Y=Y+I2(K)*Y1(K)
 730   NEXT K
 740   CALL "LINE",X*F,Y*F
 750   I2(J)=0
 760  NEXT J
 770  J=1
 780  IF I1(J)=0 THEN 820
 790  I1(J)=0
 800  J=J+1
 810  GOTO 780
 820  I1(J)=1
 830 NEXT I
 840 GOTO 90

Figure 3.2

 


Originally published as "Hypercubes" in Practical Computing, 5(4), pp 97-99, April 1982.

Acknowledgement: BASIC program based on an original FORTRAN program by C.S. Kuta
Reformatted by Jonathan Bowen, 10 April 1994.

See also: