eldorado@en.ecn.purdue.edu (David D Jansen) (03/30/91)
Here is a 3 dimentional surface graphing program for the HP48SX. Some features are: 1. It doesn't go belly up if it encounters a divide by zero or undefined result. 2. It allows the domains of the XY plane to be defined to any value ( although it centers the plot on the origin). 3. The equation is entered in X, Y, Z format not parametric form. 4. It creates a matrix of the topology of the surface which is useful for locating actual values of a max or min. It is controlled by its own plot parameters which are stored in SPAR. SPAR is defined as a list with the following elements: { lower X limit; upper X limit; X increment; lower Y limit; upper Y limit; Y increment; angle of X with horizontal; angle of Y with horizontal; flag signalling to plot a plane at Z; value of Z to plot plane; X expansion factor; Y expansion factor } The upper and lower X limit is the domain in the X coordinate. Likewise for the upper and lower Y limit. The X and Y increments set how close together the points will be. The angles allow the XY plane to change shape for better viewing. If they are changed by the same amount for consecutive plots, the graph will seem to rotate. A type of rotation by 90 degrees can be done using the Translate command on the variable TOPO. The Translate command is found in the Matrix directory. The flag determining whether an XY plane should be plotted can have the values -1, 0, 1. 0 designates no plane plotted. 1 designates the surface will be plotted on top of the plane. -1 draws the plane above the surface. Z is the value one the Z axis (the altitude) at which the XY plane will be plotted. The X and Y expansion factors scale the graph on the HP screen. Directions 1. Enter your equation and store it in varible EQ 2. Press the SFACE menu key 3. Wait for the screen to draw and then press a key to end 4. If you wish to change one of the parameters in SPAR, do so and then choose TRACE since the topology of the EQ is known. This means that recalculation is not needed to review the graph. 5. The topology and the actual graph are saved when done. Enjoy. Send comments, questions, complaints to: _______________________________________________________________________________ Dave Jansen | INTERNET: eldorado@en.ecn.purdue.edu Electrical Engineering | BITNET: eldorado%ea.ecn.purdue.edu@purccvm Purdue University | UUCP: {purdue, pur-ee}!en.ecn.purdue.edu!eldorado %%HP: T(3)A(D)F(.); DIR SFACE \<< SPAR OBJ\-> DROP 0 \-> xa xb xi ya yb yi theta phi p z h v d \<< -20 -21 -22 SF CF CF RAD ya yb FOR J J 'Y' STO xa xb FOR I I 'X' STO DEPTH 'd' STO IFERR EQ \->NUM THEN DEPTH d - DROPN 0 END IF DUP TYPE 1 == THEN DROP 0 END yi STEP xi STEP yb ya - ABS 1 + xb xa - ABS 1 + 2 \->LIST \->ARRY 'TOPO' STO { X Y } PURGE DEG -20 -21 -22 CF SF SF TRACE \>> \>> TRACE \<< SPAR OBJ\-> DROP \-> xa xb xi ya yb yi theta phi p z h v \<< 0 0 0 0 0 \-> cphi sphi ctheta stheta prv \<< PICT PURGE { # 0d # 0d } PVIEW AXIS RAD theta \pi * 180 / \->NUM DUP SIN 'stheta' STO COS 'ctheta' STO phi \pi * 180 / \->NUM DUP SIN 'sphi' STO COS 'cphi' STO ya yb FOR j j cphi * xa ctheta * - h * 65 + 0 RND # 1d * 63 j NEG sphi * xa stheta * - v * 31 + 0 RND TOPO 1 j ya - yi * 1 + 2 \->LIST GET IF p 0 \=/ THEN IF DUP DUP z < p 0 > AND SWAP z > p 0 < AND OR THEN DROP z END END + - # 1d * 2 \->LIST 'prv' STO 1 xa + xb FOR i prv j cphi * i ctheta * - h * 65 + 0 RND # 1d * 63 j NEG sphi * i stheta * - v * 31 + 0 RND TOPO i xa - xi * 1 + j ya - yi * 1 + 2 \->LIST GET IF p 0 \=/ THEN IF DUP DUP z < p 0 > AND SWAP z > p 0 < AND OR THEN DROP z END END + - # 1d * 2 \->LIST DUP 'prv' STO LINE xi STEP yi STEP xa xb FOR i ya cphi * i ctheta * - h * 65 + 0 RND # 1d * 63 ya NEG sphi * i stheta * - v * 31 + 0 RND TOPO i xa - xi * 1 + 1 2 \->LIST GET IF p 0 \=/ THEN IF DUP DUP z < p 0 > AND SWAP z > p 0 < AND OR THEN DROP z END END + - # 1d * 2 \->LIST 'prv' STO 1 ya + yb FOR j prv j cphi * i ctheta * - h * 65 + 0 RND # 1d * 63 j NEG sphi * i stheta * - v * 31 + 0 RND TOPO i xa - xi * 1 + j ya - yi * 1 + 2 \->LIST GET IF p 0 \=/ THEN IF DUP DUP z < p 0 > AND SWAP z > p 0 < AND OR THEN DROP z END END + - # 1d * 2 \->LIST DUP 'prv' STO LINE yi STEP xi STEP DEG PICT RCL 'GRPH' STO DO UNTIL KEY END DROP \>> \>> \>> EQ 'Y^2-X^2' SPAR { -5 5 1 -5 5 1 30 45 0 0 5 3 } AXIS \<< SPAR OBJ\-> DROP \-> xa xb xi ya yb yi theta phi p z h v \<< DEG { # 65d # 32d } DUP DUP { # 65d # 0d } LINE 10 h * theta COS * NEG 65 + 0 RND # 1d * 63 10 v * theta SIN * NEG 31 + - 0 RND # 1d * 2 \->LIST LINE 10 h * phi COS * 65 + 0 RND # 1d * 63 10 v * phi SIN * NEG 31 + - 0 RND # 1d * 2 \->LIST LINE \>> \>> END -- P.O.W. * M.I.A. -- You are not forgotten _______________________________________________________________________________ Dave Jansen | INTERNET: eldorado@en.ecn.purdue.edu