home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
RBBS in a Box Volume 1 #3.1
/
RBBSIABOX31.cdr
/
720k
/
3_dpltrt.bas
< prev
next >
Wrap
BASIC Source File
|
1984-07-24
|
6KB
|
171 lines
1000 '*** 3-DPLTRT.BAS *** WRITTEN FOR AN IBM PC W/GRAPHICS BOARD, ADV. BASIC
1010 '
1020 ' PLOTS THE FUNCTION Z=Z(X,Y) AND ROTATES THE SURFACE
1030 '
1040 ' NOMENCLATURE:
1050 '
1060 ' X,Y,Z 3-D COORDINATE SYSTEM; POSITIVE X RUNS HORIZONTALLY TO THE
1070 ' RIGHT; POSITIVE Z RUNS VERTICALLY UPWARD; POSITIVE Y RUNS
1080 ' PERPENDICULAR FROM THE SCREEN AND TOWARD YOU. THE ANGLE
1090 ' OF THE Y-AXIS IN THE 2-D PLANE IS SET BY YANGLE. THE
1100 ' ANGLE IS INITIALLY 15 DEGREES AND CORRESPONDS TO APPROX.
1110 ' THE 8 O'CLOCK POSITION. HOWEVER, THE 2-D PLOTTING
1120 ' SUBROUTINE SCALES THE U,V COORDINATES, IE THE FINAL ANGLE
1130 ' THAT APPEARS ON YOUR SCREEN MAY NOT BE EQUAL TO YANGLE.
1140 ' U,V 2-D COORDINATE SYSTEM TO WHICH X,Y,Z ARE MAPPED INTO.
1150 ' (XMIN,YMIN), (XMAX,YMAX) POINTS WHICH DEFINE THE EXTREMITIES OF THE
1160 ' RECTANGLE OVER WHICH FUNCTION Z IS TO BE PLOTTED. SIMILAR
1170 ' TO DEFINING A RECTANGLE WITH BASICA: LINE(A,B)-(C,D),,B
1180 ' ZEE FUNCTION Z. NAMED TO PREVENT CONFUSION WITH Z COORDINATE.
1190 ' YANGLE ANGLE OF THE Y-AXIS WITH RESPECT TO THE X-AXIS AS IT
1200 ' APPEARS IN THE 2-D PLANE.
1210 '
1220 '*** BY W. CHUCK, (7-24-84), UNDER PC-DOS V2.0, NO COMPILE W/V1.00 ***
1230 '
1240 '
1250 '--- DEFINE Z AS A FUNCTION OF X AND Y ---
1260 '
1270 ' THE FOLLOWING FUNCTION LOOKS NICE WITH XMIN=-2,YMIN=-2,XMAX=2,YMAX=2
1280 ' IGRID, JGRID=25, "Y" TO CONNECT POINTS
1290 '
1300 DEF FNZEE(X,Y)=EXP(-X*X-Y*Y)*COS(2!*(X*X+Y*Y))
1310 '
1320 ' PARAMETERS
1330 '
1340 PI=3.14159
1350 MAXMEMORY=INT(.95*FRE(0)/20)
1360 '
1370 '--- INPUTS ---
1380 '
1390 INPUT "XMIN"; XMIN
1400 INPUT "YMIN"; YMIN
1410 INPUT "XMAX"; XMAX
1420 INPUT "YMAX"; YMAX
1430 INPUT "NO. OF GRID LINES PARALLEL TO Y-AXIS"; IGRID
1440 INPUT "NO. OF GRID LINES PARALLEL TO X-AXIS"; JGRID
1450 M=IGRID*JGRID
1460 IF (M > MAXMEMORY) THEN PRINT "TOO MANY GRID LINES": GOTO 1430
1470 DIM U(M),V(M),X(M),Y(M),Z(M)
1480 INPUT "CONNECT THE POINTS (Y/N)";YN$
1490 IF (YN$="Y") OR (YN$="N") OR (YN$="y") OR (YN$="n") THEN GOTO 1530 ELSE GOTO 1480
1500 '
1510 '--- GENERATE Z=ZEE(X,Y) ---
1520 '
1530 PRINT: PRINT "PLEASE WAIT ... I'LL BEEP YOU WHEN I'M READY TO PLOT."
1540 DX=(XMAX-XMIN)/(IGRID-1): DY=(YMAX-YMIN)/(JGRID-1)
1550 N=0
1560 XA=XMIN
1570 FOR I=1 TO IGRID
1580 YA=YMIN
1590 FOR J=1 TO JGRID
1600 N=N+1
1610 X(N)=XA
1620 Y(N)=YA
1630 Z(N)=FNZEE(XA,YA)
1640 YA=YA+DY
1650 NEXT
1660 XA=XA+DX
1670 NEXT
1680 '
1690 '*** ROTATE THE SURFACE -- INCREMENT YANGLE ***
1700 '
1710 FOR YANGLE=15 TO 180 STEP 15
1720 SNY=SIN(PI*YANGLE/180): CSY=COS(PI*YANGLE/180)
1730 '
1740 '--- MAP X,Y,Z TO U,V SYSTEM ---
1750 '
1760 FOR I=1 TO M
1770 U(I)=X(I)-CSY*Y(I)
1780 V(I)=Z(I)-SNY*Y(I)
1790 NEXT
1800 '
1810 '--- CALL 2-D PLOTTING ROUTINE ---
1820 '
1830 GOSUB 2230
1840 LOCATE 25,52: PRINT "ANGLE OF Y-AXIS: ";YANGLE;
1850 '
1860 '--- CONNECT THE POINTS IF YN$="Y" ---
1870 '
1880 IF (YN$="N") OR (YN$="n") THEN GOTO 2160
1890 '
1900 '--- LINES ALONG Y-AXIS ---
1910 '
1920 FOR I=1 TO IGRID
1930 K=JGRID*(I-1)+1
1940 X1=U(K): Y1=V(K)
1950 L=K
1960 FOR J=2 TO JGRID
1970 L=L+1
1980 X2=U(L): Y2=V(L)
1990 LINE (X1,Y1)-(X2,Y2)
2000 X1=X2: Y1=Y2
2010 NEXT
2020 NEXT
2030 '
2040 '--- LINES ALONG X-AXIS ---
2050 '
2060 FOR J=1 TO JGRID
2070 X1=U(J): Y1=V(J)
2080 L=J
2090 FOR I=2 TO IGRID
2100 L=L+JGRID
2110 X2=U(L): Y2=V(L)
2120 LINE(X1,Y1)-(X2,Y2)
2130 X1=X2: Y1=Y2
2140 NEXT
2150 NEXT
2160 NEXT YANGLE
2170 LOCATE 25,20: PRINT "FINISHED";
2180 '
2190 '--- START ENDLESS LOOP ---
2200 '
2210 GOTO 2210
2220 '
2230 '*** 2-D PLOTTING SUBROUTINE ***
2240 '
2250 ' INPUT M VALUES OF U,V NOTE: U(M) AND V(M) MUST BE PREV. DIM
2260 '
2270 '--- SEARCH FOR THE LARGEST AND SMALLEST VALUES OF U,V ---
2280 '
2290 UMAX=U(1): UMIN=U(1)
2300 VMAX=V(1): VMIN=V(1)
2310 FOR INDEX=2 TO M
2320 IF(U(INDEX) > UMAX) THEN UMAX=U(INDEX) ELSE IF(U(INDEX) < UMIN) THEN UMIN=U(INDEX)
2330 IF(V(INDEX) > VMAX) THEN VMAX=V(INDEX) ELSE IF(V(INDEX) < VMIN) THEN VMIN=V(INDEX)
2340 NEXT INDEX
2350 '
2360 '--- FORM WINDOW, SET SCREEN PARAMETERS ---
2370 '
2380 ' MODES AVAILABLE:
2390 ' IF ORIGIN=0, THEN (0,0) IS ALWAYS PLOTTED.
2400 ' ORIGIN=1, WINDOW IS DETERMINED BY THE DATA
2410 '
2420 ORIGIN=1
2430 AUX1=SGN(UMAX*UMIN)
2440 AUX2=SGN(VMAX*VMIN)
2450 IF(ORIGIN=1) GOTO 2480
2460 IF(AUX1=1) THEN IF(UMAX > 0) THEN UMIN=0 ELSE UMAX=0
2470 IF(AUX2=1) THEN IF(VMAX > 0) THEN VMIN=0 ELSE VMAX=0
2480 UMEAN=.5*(UMAX+UMIN)
2490 DU=.55*(UMAX-UMIN)
2500 VMEAN=.5*(VMAX+VMIN)
2510 DV=.55*(VMAX-VMIN)
2520 U1=UMEAN-DU: V1=VMEAN-DV
2530 U2=UMEAN+DU: V2=VMEAN+DV
2540 CLS: KEY OFF
2550 SCREEN 2
2560 VIEW
2570 WINDOW (U1,V1)-(U2,V2)
2580 '
2590 '--- DRAW U,V AXES ---
2600 '
2610 BEEP
2620 IF(ORIGIN=0 OR (AUX1 < 0 AND AUX2 < 0)) THEN LINE(U1,0)-(U2,0): LINE(0,V1)-(0,V2) ELSE LINE(U1,V1)-(U2,V1): LINE(U1,V1)-(U1,V2)
2630 '
2640 '--- PLOT POINTS ---
2650 '
2660 FOR INDEX=1 TO M
2670 PSET(U(INDEX),V(INDEX))
2680 NEXT INDEX
2690 RETURN