Surface plotting program for the HP85

The HP85 minicomputer has a graphics facility as part of its BASIC interpreter; this program (figure 1) was written for the HP85 in order to plot a three dimensional representation of up to 80 x 80 values (retrieved from a data file). Two alternative perspectives are selectable: isometric or oblique, an example of an isometric plot is seen in figure 2.

The values to be plotted are arranged in the two dimensional array: M, this represents a square of edge length L with the values defined at intervals of P. The perspective appearances of the square are shown in figures 3a and 3b. The surface is formed by calculating the position of a point for each pair of x and y coordinates and joining this point to its four nearest-neighbours by straight lines. The height is proportional to the value stored for that position and equals: F x M(x,y), where F is a vertical scaling factor. The position (in space) is shown in figures 3a and 3b. Point Q is defined by three spatial coordinates, but to be represented on the page these three numbers need to be combined to give the two coordinates that define the point's position on the page; this is achieved by statements 4300 and 4500.

During plotting the values are examined sequentially in x; when a line has been fully examined the process is repeated for the next value of y. Once the position on the page has been determined a line is drawn from the previous position to the new point, then a second line is drawn to the corresponding x position of the previous line of data, this results in the 'cross-grid' appearance of the surface.

Hidden detail is suppressed using statements 4700 to 5500: the maximum pen position is recorded for each scan in the x direction (using arrays S and T); during all subsequent scans (ie, for increasing values of y) the points will be plotted only if their position on the page is higher than the previously maximum.

L. Mayes
Univ of Essex

Figure 1

1000 COM INTEGER I1,L,M(80,80),P,P1,Q,X,Y
1100 COM S(160),T(160) ! Used for hidden line suppression
1200 COM Z(80,1) ! Used to form cross grid
1300 CLEAR @ DISP "Filename"; @ INPUT W$
1400 ASSIGN# 1 TO W$ @ READ# 1;L @ READ# 1; P
1500 FOR Y = 0 TO L/P @ FOR X = 0 TO L/P
1600 READ# 1; M(X,Y) @ NEXT X @ NEXT Y
1700 READ#1; Z$ @ ASSIGN# 1 TO *
1800 PENUP @ DISP @ DISP "Isometric plot"; @ INPUT G$
1900 IF UPC$(G$[1,1]) = "Y" THEN 2200
2000 IF UPC$(G$[1,1]) = "N" THEN 2300
2100 DISP "PLEASE ANSWER 'YES' OR 'NO'" @ GOTO 1800
2200 I1 = 1 @ DISP "ISOMETRIC SELECTED" @ GOTO 2400
2300 I1 = 0 @ DISP "OBLIQUE SELECTED"
2400 DISP @ DISP "Vertical scale factor"; @ INPUT F
2500 GOSUB 3500 ! Initialise variables
2600 GOSUB 3900 ! Draw axes of picture
2700 FOR Y = 0 TO L STEP P
2800 X = 0 @ MOVE L-X+Y, Y ! Get plotter back to start of line
2900 FOR X = 0 TO L STEP P
3000 M = F*M(X/P,Y/P)
3100 GOSUB 4300 ! Plot the point
3200 NEXT X @ NEXT Y
3300 BEEP 100,100 @ DISP "Scan completed"
3400 PENUP @ GOTO 1800
3500 FOR Q = 0 TO L/P
3600 Z(Q,0) = L-Q*P @ Z(Q,1) = Q*P*I1 @ NEXT Q
3700 FOR S = 0 TO 160 @ S(S) = 0 @ T(S) = 0 @ NEXT S
3800 RETURN
3900 GCLEAR @ PENUP
4000 SCALE 0, 2*L, 0, (2+I1)*L
4100 PLOT 0, I1*L @ PLOT L, 0 @ PLOT 2*L, L @ PLOT L, 0
4200 RETURN
4300 P1 = L-X+Y
4400 ! P1 is the horizontal position on the page
4500 Q1 = Y+M*L/400 + X*I1
4600 ! Q1 is the vertical position on the page
4700 S(P1/P) = MAX(S(P1/P),Q1)
4800 ! Select the highest value - don't draw hidden line
4900 IF T(P1/P) = S(P1/P) THEN MOVE P1, S(P1/P)
5000 ! We've already drawn a line to this point
5100 IF T(P1/P) < S(P1/P) THEN DRAW P1, S(P1/P)
5200 ! Draw a new line
5300 IF Q1 >= S(P1/P) THEN DRAW Z(X/P,0), Z(X/P,1)
5400 !Draw cross grid line
5500 IF Q1 >= S(P1/P) THEN DRAW P1, S(P1/P) ! Retrace path
5600 Z(X/P,0) = P1 ! Remember position of horizontal coord of line
5700 Z(X/P,1) = S(P1/P) ! Remember the vertical coord
5800 T(P1/P) = S(P1/P) ! Used to check if point has already been plotted
5900 RETURN
6000 END

Figure 2

Surface plot

Figure 3a

Isometric view

Figure 3b

Oblique view


This article was first published in ELECTRONIC ENGINEERING, 54, No 670; OCTOBER 1982 pp 31-33


Electronics Index | Feedback

Last updated 13 November 2001,    © Lawrence Mayes. 1982, 2000 & 2001