GR3D Plot a three-dimensional graph with hidden line removal. ----begin documentation---- Program: GR3D Author: John P. Powers (jpp@cpdvax.csc.ti.com) Date: March 19, 1992. Synopsis: GR3D plots a three-dimensional graph on the TI-85 calculator. Instructions: 1) Modify GR3DEQ to compute z as a function of x and y. GR3DEQ already contains some equations to get you started. To use one of the starter equations, change the Goto at the beginning to jump to one of them. 2) Modify GR3D to set the coordiates of the observer (XE, YE, ZE), the x and y domain (XL, XH, YL, YH) and the grid density (GRID). You don't need to change these values to get some reasonable graphs. 3) Run GR3D from the home screen. There are three subroutines which accompany the main routine: GR3DEQ - define your equation here, GR3DPLOT - Wright's hidden-line removal algorithm, GR3DLEFT - auxiliary routine for GR3DPLOT. Several variables in GR3D are pre-defined: XE=2, YE=1, ZE=1 are the coordinates of the observer's eye. XL=-7, XH=7, YL=-7, XH=7 are the limits of the domain for x and y input to the function to be graphed. The current settings create a graph centered at the origin. GRID=11 is the grid density of the graph. This setting will create an eleven by eleven square graph. A lower setting will produce a faster but courser picture. High settings take longer and begin to clutter the TI-85 screen as the fairly low device resolution is approached. GR3D first builds matrices of transformed and projected coordinates for function values at the grid point intersections. The program displays a count down to zero as these matrices are computed. The program then scales the transformed points to fit the entire graph on the screen. Finally the graph is drawn with hidden lines removed. The entire process takes about 5.5 minutes. GR3DEQ contains four equations for a starter. Change the Goto in the first line of this program to Goto EQ1, ..., EQ4 to select which equation should be plotted. EQ1: z = cos |x+y*i| XL=-7, XH=7, YL=-7, YH=7 (set these in GR3D) Radians mode. See picture COSXY. EQ2: z = e^-|x-1+y*i| + e^-|x+1+y*i| XL=-2.5, XH=2.5, YL=-2.5, YH=2.5 See picture EXPXY2. EQ3: z = R - sqrt(1-(x^2+y^2)), if norm [x,y,R] < 1. 0, otherwise. XL=-1.2, XH=1.2, YL=-1.2, YH=1.2 R=.7 (This could be set once in GR3D.) This creates a depression in the plane z=0 by pressing a sphere into its surface. R is a fraction in the domain [0,1] which indicates the depth that a unit radius sphere is pressed into the plane. See picture SPHERE3D. EQ4: z = e^-|x+y*i| XL=-1.2, XH=1.2, YL=-1.2, YH=1.2 See picture EXPXY. Memory requirements: PROGRAMS GR3D 1548 bytes GR3DEQ 186 bytes This varies according the complexity of F(x,y). GR3DLEFT 90 bytes GR3DPLOT 845 bytes REALS I, J, K, S, U, V, x, y, z, 135 bytes CX, CY, DX, DY, S1, S2, S3, S4, U1, U2, V1, V2, VK, UH, UL, VH, VL, KM, KX, VM, VX, XL, XH, YL, YH, XE, YE, ZE, X0, Y0, 480 bytes GRID 18 bytes MATRICES and VECTORS H 1277 bytes L 1277 bytes *RX 1448 bytes *RY 1448 bytes *X 127 bytes *Y 127 bytes * These matrices and vectors take up more memory as GRID increases. Total memory required: approximately 9006 bytes. The program releases the space used by the matrices and vectors when it finishes. ----end documentation---- ----begin ascii---- \START\ \COMMENT=Program file dated 12/11/92, 07:48 \NAME=GR3D \FILE=gr3d.85P 2\->\XE:1\->\YE:1\->\ZE 11\->\GRID .6\->\R \(-)\2.5\->\XL:2.5\->\XH:\(-)\2.5\->\YL:2.5\->\YH GRID+1\->\dim X:GRID+1\->\dim Y {GRID+1,GRID+1}\->\dim RX {GRID+1,GRID+1}\->\dim RY XE\^2\+YE\^2\\->\S1 \sqrt\S1\->\S2 \sqrt\(S1+ZE\^2\)\->\S3 (S2*S3)\^-1\\->\S4 127\->\dim H:127\->\dim L Fill(63,L) Fill(1,H) Func FnOff AxesOff 1\->\xMin:1\->\\Delta-x\ 1\->\yMin:1\->\\Delta-y\ \(-)\9\E\999\->\UH:\(-)\UH\->\UL:UH\->\VH:UL\->\VL (XH-XL)/GRID\->\DX (YH-YL)/GRID\->\DY XH\->\X0 If XE<0:Then \(-)\DX\->\DX XL\->\X0 End YH\->\Y0 If YE<0:Then \(-)\DY\->\DY YL\->\Y0 End 64\->\CX:32\->\CY For(I,1,GRID+1) X0-(I-1)*DX\->\X(I) Y0-(I-1)*DY\->\Y(I) End For(I,1,GRID+1) For(J,1,GRID+1) X(I)\->\x:Y(J)\->\y GR3DEQ (XE*y-YE*x)/S2\->\U (ZE*(x*XE+y*YE)-S1*z)*S4\->\V U\->\RX(I,J):V\->\RY(I,J) min(U,UL)\->\UL:max(U,UH)\->\UH min(V,VL)\->\VL:max(V,VH)\->\VH End Disp GRID+1-I End 9\E\999\->\S If UL\<>\0:min(S,62/abs UL)\->\S If UH\<>\0:min(S,62/abs UH)\->\S If VL\<>\0:min(S,30/abs VL)\->\S If VH\<>\0:min(S,30/abs VH)\->\S For(I,1,GRID+1) For(J,1,GRID+1) iPart (S*RX(I,J)+CX)\->\RX(I,J) iPart (S*RY(I,J)+CY)\->\RY(I,J) End End ClDrw If abs XE\>=\abs YE:Then For(I,1,GRID+1) For(J,2,GRID+1) RX(I,J-1)\->\U1:RY(I,J-1)\->\V1 RX(I,J)\->\U2:RY(I,J)\->\V2 GR3DPLOT End If I\U1:RY(I,J)\->\V1 RX(I+1,J)\->\U2:RY(I+1,J)\->\V2 GR3DPLOT End End End Else For(J,1,GRID+1) For(I,2,GRID+1) RX(I-1,J)\->\U1:RY(I-1,J)\->\V1 RX(I,J)\->\U2:RY(I,J)\->\V2 GR3DPLOT End If J\U1:RY(I,J)\->\V1 RX(I,J+1)\->\U2:RY(I,J+1)\->\V2 GR3DPLOT End End End End 0\->\X:0\->\Y 0\->\H:0\->\L 0\->\RX:0\->\RY \STOP\ \START\ \COMMENT=Program file dated 12/11/92, 07:48 \NAME=GR3DEQ \FILE=gr3deq.85P Goto EQ1 Lbl EQ1 Radian cos abs (x,y)\->\z Return Lbl EQ2 e^\(-)\abs (x-1,y)+e^\(-)\abs (x+1,y)\->\z Return Lbl EQ3 .7\->\R If norm [x,y,R]<1:Then R-\sqrt\(1-(x\^2\+y\^2\))\->\z Else 0\->\z End Return Lbl EQ4 e^\(-)\abs (x,y)\->\z Return \STOP\ \START\ \COMMENT=Program file dated 12/11/92, 07:48 \NAME=GR3DLEFT \FILE=gr3dleft.85P U1\->\KM U2\->\KX V1\->\VM V2\->\VX If KM>KX:Then U2\->\KM U1\->\KX V2\->\VM V1\->\VX End \STOP\ \START\ \COMMENT=Program file dated 12/11/92, 07:48 \NAME=GR3DPLOT \FILE=gr3dplot.85P V1\>=\H(U1)\->\T1 V2\>=\H(U2)\->\T2 V1\<=\L(U1)\->\G1 V2\<=\L(U2)\->\G2 If (T1 and T2) or (G1 and G2):Then Line(U1,64-V1,U2,64-V2) Goto UPDATEHL End If T1+T2+G1+G2==0:Goto UPDATEHL GR3DLEFT If KM==KX:Goto PLOTHIGH 0\->\F1:0\->\F2 For(K,KM,KX) VM+(VX-VM)*(K-KM)/(KX-KM)\->\VK If VK>H(K) or VK\KM:Then min(max(VK,L(K)),H(K))\->\V1 K\->\U1 End 1\->\F1 KX\->\K End End For(K,KX,KM,\(-)\1) VM+(VX-VM)*(K-KM)/(KX-KM)\->\VK If VK>H(K) or VK\KX:Then min(max(VK,L(K)),H(K))\->\V2 K\->\U2 End 1\->\F2 KM\->\K End End If F1 and F2:Line(U1,64-V1,U2,64-V2) Goto UPDATEHL Lbl PLOTHIGH If VX>H(U1):Then Line(U1,64-H(U1),U1,64-VX) Else If VM\H(U1) max(V2,H(U2))\->\H(U2) min(V1,L(U1))\->\L(U1) min(V2,L(U2))\->\L(U2) If abs (U1-U2)\<=\1:Return GR3DLEFT For(K,KM+1,KX-1) VM+(VX-VM)*(K-KM)/(KX-KM)\->\VK max(VK,H(K))\->\H(K) min(VK,L(K))\->\L(K) End \STOP\ ----end ascii---- ----begin uue---- begin 644 gr3d.85g M*BI423@U*BH:#`!';S192`LT63!OV#1915%$ M,`!NV6^A-$19"S1$66\T64P+-%DP;]YO1#8T``LT0UAN1#,R``LT0UEOW1`S M22]$,0`O-D=2241@1#$`$6\T6#!A$#-)840Q`!%P-$18"S-8$#-)$6\T63!A M$#-)840Q`!%P-$19"S-9$#-)$6_>;]T0,TDO1#$`+S9'4DE$8$0Q`!%OW1`S M2B]$,0`O-D=2241@1#$`$6\S6!`S21$+,@%X;C-9$#-*$0LR`7EO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#1635$S3!`T53$1;I80-%4Q+T0V-`!A,TP0-%4Q M$2\T53$O1#8T`&$T5DT1;]YOX%501$%414A,`&\3$#16,2\S2!`T53$1$0LS M2!`T53$1;Q,0-%8R+S-($#15,A$1"S-($#15,A%O%!`T5C$O,TP0-%4Q$1$+ M,TP0-%4Q$6\4$#16,B\S3!`T53(1$0LS3!`T53(1;]BB$#15,6$T53(14T0Q M`&[?;SI'4C-$3$5&5&_=$#-++S1+36!$,0`O-$M8840Q`!%O-%9-8!`T5EAA M-%9-$7`0,TMA-$M-$7$0-$M8831+31$+-%9+;Q,0-%9++S-($#-+$1$+,T@0 M,TL1;Q00-%9++S-,$#-+$1$+,TP0,TL1;]X)`/(#$05#3U-86?(#\`,````` M`'\```````````````````&"P``````````````````"PC`````````````` M`````C0(``````````````````0(#@`````````````````(#!&````````` M````````#!(00````````````````!,1('`````````````````0D*"(```` M````````````(&!`A@```````````````"`@<($```````````````!04(B! M@```````````````2$R?/_```````````````(2#<_"/_P````````````$" MGZ#@@N3````````````"@>'`600?^`````/``````F.P<(<$"$\```!\L``` M``0%2$ M<,0.'B$$$./P820Z`` M0];\1Z?P@B!@L?S-$2Q``/[[R)Q"/@0@D&#X,(B_@``!_A#H0A'X0(B_]BB$ MX0```'F7D(0@A^`_\<&D0QD````<>A"_^((_T<"@0BV&````#L(3R$>"$R"@ MD*$0;`````/$+1!!9!#`F1"0K!`````!O_(0@AP@<04)$$(@`````/!"$((+ M((T"!0BAH``````X1!"$$.""`P(%&$``````#(0@A!!8@P2%`@6```````/_ M^0@@AP3$1(6"````````T$?\(($$)"A$;````````#!""T"!Q!@8*#`````` M```,@A#@@C@(!O_``````````\0070((%O]O```````````_((.$%_\%\``` M`````````/B"9!XVSP`````````````'Q!QD.;```````````````#XW_\X` M```````````````!^``````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````)`/(#$05%6%!86?(#\`,``````'_^'X`````````` M``````&`P?!\```````````````#___`"^``````````````#`P'X!'?@``` M`````````!'__IX@OG@```````````!_G_D!P&__P``````````!O^[A`*`3 MYSP`````````!\QS@@"0"-S#P````````!@7W@(!"`1__#@````````C^>($ M`08#C,<'````````?$<$!`(!!0(PX>```````(&\"`@"`(C!#!X<``````,# MQ!`(!`!0(,-C`X`````$?@@1_P0`(!`CP,!P````#X@0?A#X`%`,/#`QC@`` M`!`0%\`@#@",`LP,#@'````@(_A`(!&`@@$#`S'`,```1_Q`@$`080$"P,#@ M.,```/B`@(!`(!H`Q"`S&`<```$!`($`@"`$`"@8#`8,```"`@$!`(!`!P`0 M!#8!D```!`0"/__`0`B`+`-!@&````C__\0"/(`(8$,`@&#````?$`@$`@/` M$!"`@V`;````(!`("`0!,!`-`&P8!````$`@$`@$`0P@`@`0!A@```!`0"`0 M"`(#(`6`+`&@````@$`@$!`"`.`$8$,`0````?____X0!`"8"!A`P8````(! M`(!!^`@`AA`&@#8````,`@$`0$>(`0&0`0`(````$`0!`(!`>`(`<`+`$``` M`#X(`@$`@"<$`$P$,"`````!_P0"`(`@Y`"#!`P@``````#_@@$`0!P`@,@# M0````````'_!`$`3@0`X`(``````````/X"`$'(`)@$```````````!X@"`. M`$&&````````````!\!`"<"`:``````````````\0`@Y`!`````````````` M`\`0!P`@```````````````X(`3`0```````````````!R`$,$`````````` M``````#@"`R`````````````````'!`#``````````````````.0`@`````` M````````````<`0```````````````````X$```````````````````!R``` M`````````````````#`````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```*`/(#$09%6%!863+R`_`#```````````````````````````````````` M````````````````````````````````````````````````````````/``` M`````````````````,/\``````````````````$`@_@````````````````# MX0,'_@``````````````#!__PW?P`````````````!`8,#^@'_`````````` M```____^0#?/@```````````P,"#^?A"?'@``````````>$!/S\'@9O'@``` M``````8?_]CA`6!&>'@````````(#`PO@@(0)X8'````````'A`3\@(""#C! MF,```````&'__(__A`;,,'`P``````"`08'X&'P!`PV.#P`````!\)__$"`S M`L"#`9CP````!@_D#"/X0,(P;.!P#P````@&"!/_Q\`T"#`9CS#P```?"!'] M\#XP"`;,!P#@#```(/_^QW`:##8!`PS!G!@``$!@07W/(0-!AL#0,@,@``#P M@)^.@,#`@&@P<`\`P``!#__L&(!@(V`8#8X(\P```@8&$>"`D!089@,!D`P` M``0("?Y!`(P(!H&$X'`8```/__Y`@0$"-@&`:!F/(```,"`@0((!`4&"8!@' M`,```$`@0($?`@"`0AAF#,&```#X0("?Y/(`X#0&@9`R```#!___Y`0.`1@, M`8!P#```!`,"`@@("8$$,P9@S@@```^$!`0("`AB`T#(&0&0```0?P@($!`0 M&@"`.`<`8```$!#___X0(`8!8"8$X,```"`@("!!_"`)@AA!A!D```!X0"!` M0$/@$&0&@&@&````!_A`0("`7!`<`8`8#``````'\("`@(,@$P)P9Y`````` M``__X0"`X"#"#(!@`````````!^!`)@@-`.`0```````````>0$&0`P"8(`` M``````````0&/(#/`````````````"`?"`/ MA`/P```````````!@,/P&'X"#X``````````!GD`CR`QY`9X``````````@' MX0#X0!\(!^`````````8#!\!A^`P_`0?````````)Y`$\@">0"/(!/`````` M`$!X"`X!`0"/`````!\(!@"&(!`_"`?A`/ MP```!@^`V!`:`0$/@,'P&#P```@&>08@!`("`GD`SR`8```?"`8!H`L"`@(' MX0#\(```(/@-@$`(Q`0$!!\!@\```$!GD$"P$#0$"`@,\@&```#P@&`@C!`/ MB`C^$`_"```##\!8&0(@$'__(?@(/```!`8\A`4!H!`0($#'D!@```\(`P(" M`$`@$"!!`'P@```P_`;!C8"P("!`GX##P```0"/(,%!!#$`@0^1Y`8```/A` M/@S@(0-`0(X(!\(```,'P&'_&!H`^$#T.`P\```$`SR`380&`0?_A.>0"``` M#X0#\(-B&<$!`@^`?A```#!\!@^`T:`R`@([@,'@``!`,\@&>/S@#@($[GD` MP```^$`_"`?_'!GD!_@'X0````?@(/@,'P,@'__\!!X`````'D`GD`3PX#`_ M(\@$``````'`0'@(#QY'P$`X"```````/(!'D!CS^SR`9Y````````/P@'P@ M#X0#\(!@````````#X##\!A^`@^`P`````````!Y`(\@,>0&>0`````````` M!^$`^$`?"`8````````````?`8?@,/P$`````````````/(!'D!CR``````` M```````/P@'P@#```````````````#X##\!@```````````````!Y`(\@``` M`````````````!^$`P``````````````````?`8```````````````````/( M````````````````````,``````````````````````````````````````` M```````````````````````````````````````````````````````````` =````````````````````````````````````