Hypercubes
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.
X0, Y0 and F (the coordinates of the new
origin and the size factor) will probably need to be adjusted (i.e.
lines 410 to 520 will have
to be changed as necessary). Line 670 moves the
current position to the coordinates (X,Y).
(In fact it also draws a point at that position but this is not
necessary for the program to work.) Line 740
draws a line from the current position to a new position at coordinates
(X,Y).
4.0*ATN(1.0). Apart from the points noted
above the program is written in "standard" BASIC and there should be
few problems transfering the program to another computer with the
necessary hardware and software graphics capabilities.
Acknowledgement: The above plots were generated using a Java program which is accessible on-line, written by Andy Wallace.
Z
W .
. .
. .
. .
. .
. .
..
.__________. . . . X
.
.
.
.
.
.
Y
Z
W .
. .
. .
. .
. .
. .
..
.__________. . . . X
/ /
/ /
/ /
/__________/
.
.
Y
Z
W .
. .
. .__________
. /| /|
. / | / |
/ | / |
/__________/ |
| .| | |
| |______|___| . . . X
| / | /
| / | /
|/ |/
|__________|
.
.
Y
Z
.
W .
. __________
. /|\ . /|\
./ | \ . / | \
/. | \ . / | \
/__________/ | \
|\ | \_|\_______\
| \ |____/||_\_| /|
| \/\ / || \ \ / |
| /\ \/ || / \ \/ |
| / \/_________\/\ |
|/____|___|| | \ |
\ | \|_\____|__\| . . . X
\ | / \ | /
\ | / \ | /
\ |/ \ |/
\|_________\|
.
.
Y
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 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
See also: