home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / sources / hp48 / 303 < prev    next >
Encoding:
Text File  |  1993-01-22  |  34.2 KB  |  1,174 lines

  1. Newsgroups: comp.sources.hp48
  2. Path: sparky!uunet!seq!spell
  3. From: Charles Patton <charliep@hpcvrs.cv.hp.com>
  4. Subject:  v08i008:  suite3d.cp - Suite3D v4.0, Part01/02
  5. Message-ID: <cshp48-v08i008=suite3d.cp.233944@seq.uncwil.edu>
  6. Followup-To: comp.sys.hp48
  7. Sender: spell@seq.uncwil.edu (Chris Spell)
  8. Organization: Univ. of North Carolina @ Wilmington
  9. Date: Fri, 22 Jan 1993 04:40:41 GMT
  10. Approved: spell@seq.uncwil.edu
  11. Lines: 1165
  12.  
  13. Checksum: 2833039556 (verify with brik -cv)
  14. Submitted-by: Charles Patton <charliep@hpcvrs.cv.hp.com>
  15. Posting-number: Volume 8, Issue 8
  16. Archive-name: suite3d.cp/part01
  17.  
  18. BEGIN_RDME suite3d.rdm
  19. _Suite3D Version 4.0 Additions and Changes_
  20.  
  21. This version builds on the GRIDMAP functionality of 3.0 to provide for
  22. parametric surface plotting, PARSURFACE. In addition, it changes the
  23. conventional interpretation of XXleft, Xright, etc. from indicating
  24. the output range to the indicating the input range. This allows
  25. PARSURFACE to also use these specifications as well as continuing to
  26. use the normal view-volume parameters to describe the 3D region.
  27.  
  28. With the addition of the parametric surface plot, we pretty much
  29. complete the graphical tecniques for functions of two variables. In
  30. fact, while this document has referred to  3D Plotting, this is
  31. something of a misnomer.  A better name would be "visualization
  32. techniques for functions of two variables." This would cover the
  33. perspective view of the graph of a scalar function of two variables
  34. (WIREFRAME), the slicing view of a scalar function of two variables
  35. (Movie), the contour-map view of a scalar function of two variables
  36. (psContour), the slope interpretation of a scalar function of two
  37. variables (SlopeField), the mapping grid visualization of a
  38. 2-vector-valued function of two variables (GRIDMAP), and the image
  39. graph of a 3-vector-valued function of two variables (PARSURFACE).
  40.  
  41. _Suite3D Version 3.0 Additions and Changes_
  42.  
  43.  
  44. Version 3.0 adds one new feature, GRIDMAP, which presents a method
  45. of visualizing maps from the plane to the plane. The idea is simple:
  46. draw the image under the mapping function of a rectilinear grid residing
  47. in the input plane. Besides being used in various graphing programs, such
  48. as 'f(z)' by Lascoux Graphics, it has been shown to be an effective aid
  49. in understanding iterated maps of the plane (see "Grid Imaging for a Two-
  50. Dimensional Map," Judd, Mees, Aihara, and Toyada, _International Journal
  51. of Bifurcation and Chaos_, V1 N1, March 1991.)
  52.  
  53. As usual, POSTSCRIPT output capabilites for this plotting method are
  54. included and, as usual, you can leave them out if you are short on
  55. room.
  56.  
  57. _Suite3D Version 2.0 Additions and Changes_
  58.  
  59. In addition to the slopefield, pseudo-contour, oblique perspective,
  60. Phong-Shaded, and movie plotting capabilities, version 2.0 introduces
  61.  
  62. *Major Feature*  POSTSCRIPT(TM) output for all the graphing routines in a
  63. form suitable for editing/viewing with Adobe Illustrator(TM), sending to a
  64. POSTSCRIPT printer, or including in a \special {\illustration} TeX(TM)
  65. command. Included is a PS-output version of the standard DRAW command.
  66.  
  67. All the output is in terms of line segments, Bezier curves, and fill-
  68. regions so that it can be scaled to arbitrary size or printed at
  69. very high resolution without loss of smoothness.
  70.  
  71. If you have ever wanted to produce high-quality function-graph illustrations
  72. with the flexibility that '48 provides, this is for you! (You might be able
  73. to tell that I'm pretty happy with this item.)
  74.  
  75. *Significant Addition* (relatively) fast WIREFRAME graphing in oblique
  76. 3D perspective with adjustable grid spacing.
  77.  
  78. *Easier View Switching* The 3D plotting parameters have been rearranged
  79. so that all the routines can compute an appropriate XRNG and YRNG from
  80. these. Once set, you can go from view to view with no manual adjustments.
  81.  
  82. *Other Enhancements*
  83.    A Movie single-step has been added so that you can easily step through a
  84.    Movie frame-by-frame.
  85.  
  86.    All routines now use user-specified number of X-increments and Y-increments,
  87.    as appropriate, so that the WIREFRAME grid, the lattice of slopefield
  88.    segements, and number of Movie frames, etc. all references these numbers
  89.    rather than being "hard coded" as in the earlier versions.
  90. END_RDME
  91.  
  92. BEGIN_DOC Suite3D.doc
  93. @ Version 4.0 @
  94.  
  95. _Introduction_
  96.  
  97.      The programs contained in this document comprise a suite of 3D
  98. graphing/viewing utilities for the HP-48 (an HP-28 version will be
  99. forthcoming provided sufficient interest.)
  100.  
  101.      We had several requirements to consider in creating these
  102. programs. Our aims were that they be (1) purely user code, (2)
  103. relatively short, and (3) psychologically effective.  Aims (1) and (2)
  104. are due to our target audience of educators, many of whom have little
  105. contact with technology beyond their use of the HP-48 or HP-28. We
  106. expect that, in many situations, one user will obtain the code in
  107. printed form, enter it into their machine, and transmit it to others
  108. via the infrared I/O.
  109.  
  110.      In exploring visualization techniques on a variety of machines we
  111. found that increasing "realism" (read: ray-traced, Phong-shaded,
  112. hidden-line, etc.) in the graphical presentation of functions of two
  113. variables did not necessarily correlate with increasing ease of
  114. comprehension. These programs represent the results of some of these
  115. experiments (including time-to-completion as an important factor).
  116.  
  117.      We invite you to try them out and experiment yourself. All
  118. suggestions, additions, corrections, insights, commentary, and
  119. criticisms are welcome.
  120.  
  121. _NO WARRANTY_
  122.     This work is provided on an "as is" basis. Hewlett-Packard Co.
  123. provides no warranty whatsoever, either express or implied regarding
  124. the work, including warranties with respect to its merchantability or
  125. fitness for any purpose whatsoever.
  126.  
  127. _Copyright_
  128.    Copyright (C), 1991, Hewlett-Packard Co. Permission to copy all or
  129. part of this work is granted provided that the copies are not made or
  130. distributed for resale (excepting nominal copying fees) and the
  131.  _NO WARRANTY_ and this copyright notice are included verbatim. Other
  132. permissions can be arranged by contacting the author.
  133.  
  134. _Correspondence_
  135.  
  136. Correspondence on Suite3D suite should be sent to Charles Patton at one of the
  137. following addresses:
  138.  
  139. snail-mail:
  140.           M.S. 5U-L9
  141.           Hewlett-Packard Co.
  142.           1000 N.E. Circle Blvd.
  143.           Corvallis, OR 97330
  144.  
  145. e-mail:
  146.           charliep@cv.hp.com    (for Internet hosts)
  147.           hplabs!hpcvrs!charliep (for UUCP hosts)
  148.  
  149. _Organization_
  150.  
  151.      Analogous to the built-in plotting routines, all the Suite3D
  152. programs assume that the function of interest is stored in EQ.
  153. Further, they assume that the function is represented as an expression
  154. in the variables 'X' and 'Y' (e.g. u,v -> sin(u+v) is represented as
  155. 'SIN(X+Y)' in EQ). 
  156.  
  157. N.B.> Insure that 'X' and 'Y' are formal (no variables 'X' and 'Y' 
  158. N.B.> along the current path).
  159.  
  160. N.B.> Most of these routines produce their best-looking output with the
  161. N.B.> machine in "CONNECT" mode ( the CNCT button in the MODES menu 
  162. N.B.> toggles this mode.) 
  163.  
  164. N.B.> While you are examining the MODES menu, be sure to check that the 
  165. N.B.> the machine is in SYMBOLIC EVALUATION mode ( SYM button.)
  166.  
  167.      The viewing region and other Suite3D plotting parameters are stored
  168. in the sub-directory, VPAR. VPAR contains the variables:
  169.     Xleft and Xright,
  170.        controlling the width of the view-volume,
  171.     Yfar and Ynear,
  172.        controlling the depth of the view-volume,
  173.     Zlow and Zhigh,
  174.        controlling the height of the view volume,
  175.     XXleft and XXright,
  176.        controlling the horizontal range of the GRIDMAP and
  177.        PARSURFACE input region,
  178.     YYlow and YYhigh,
  179.        controlling the vertical range of the GRIDMAP and
  180.        PARSURFACE input region,
  181.     Xe, Ye, and Ze,
  182.        the coordinates of the eye-point,
  183.     Nx and Ny,
  184.        the number of X- and Y-increments desired, and
  185.     hidden
  186.        the flag indicating that hidden-line plotting should be used
  187.        in the Yview plotter.
  188.  
  189.       VPAR was implemented as a sub-directory so that the REVIEW key can be
  190. used to examine the state of these variables in a way which reminds
  191. the user of their meaning.
  192.  
  193.      Other than VPAR, the programs here are organized into a single
  194. directory for convenience.  Inter-dependence of the programs and other
  195. variables is noted in the program description.
  196.  
  197. _Oversized PICTs_
  198.  
  199.      All of the programs seem to work reasonably well with arbitrary sized
  200. PICT grobs. However, ShapeToShade only draws to the upper-left-hand-corner
  201. of the grob, and Movie only shows the display-sized region of the grob (what
  202. else could it do?) The POSTSCRIPT plotting routines scale their results to
  203. the size of the default PICT grob, but this should pose few problems.
  204.  
  205. _Descriptions of the Programs_
  206.  
  207. SlopeField:
  208.      The SlopeField program plots a lattice of line segments whose
  209. slopes represent the function value at their centerpoint. Using
  210. SlopeField to plot F(X,Y) allows your eye to pick out integral curves
  211. of the differential equation dy/dx=F(x,y). It is quite useful in
  212. understanding where the "arbitrary constant" in anti-derivatives comes
  213. from.
  214.  
  215. The number of lattice points per row is determined by Nx and the
  216. number of lattice points per column is determined by Ny. The input region
  217. sampled is given by Xleft < X < Xright and Ynear < Y < Yfar.
  218.  
  219. psContour:
  220.      The psContour program (pseudo-contour) program uses SlopeField to
  221. produce a fast contour plot of the current function. By plotting the
  222. direction field perpendicular to the gradient of the function it
  223. allows your eye to pick out the integral curves (contours) without
  224. actually plotting them. The apparent contours are evenly spaced
  225. visually and so give no information on how steep the graph is at any
  226. particular point.
  227.  
  228. The number of lattice points per row is determined by Nx and the
  229. number of lattice points per column is determined by Ny. The input region
  230. sampled is given by Xleft < X < Xright and Ynear < Y < Yfar.
  231.  
  232. YView:
  233.      The YView program provides an oblique-view, perspective, 3D
  234. surface plot (viewing toward increasing Y). This produces a sequence of
  235. plots of the function along Y=constant lines in the input domain. These
  236. plots are perspective-projected onto the view-plane relative to the eye
  237. point. In overhead view:
  238.                                    Yfar
  239.        +----------------+
  240.  .     |        |  .
  241.        |        |
  242.  Xleft |      /\    |Xright
  243.     .  |     /  \       | .
  244.      . |     .   .      |.
  245.        +----------------+
  246.        .      .  .      . Ynear
  247.            .      .       .
  248.       .     . .    .
  249.    ---------.----..---.--------------------- view-plane
  250.            .  .   .
  251.          . . .
  252.            *  eye-point (Xe,Ye,Ze)
  253.               |<- XRNG ->|
  254.  
  255.      The same picture holds with Zlow replacing Xleft, Zhigh replacing Xright,
  256. and YRNG replacing XRNG (and turning your head 90 degrees to the right.)
  257.  
  258.      In short, Ynear and Yfar and Ny determine the Y-inputs sampled; 
  259. Xleft, Xright, and the eye-point determine the XRNG; Zlow, Zhigh,
  260. and the eye-point determine the YRNG. This computation is performed by
  261. the utility, SetWindow.
  262.  
  263.      This is a simple "divide-by-depth" method for perspective
  264. plotting where the viewplane is always 1 unit from the viewpoint and
  265. is parallel to the x-z plane. Since the perspective transformation in
  266. the case can be implemented by a simple change of coordinates,
  267. plotting individual sections is no slower than ordinary plots.
  268.  
  269.      If 'hidden' is non-zero, each plot of a sampled point will erase the
  270. column of pixels below it. Since the curves are plotted back-to-front,
  271. this results in a hidden-line plot of the surface. It works best if
  272. RES is #1 or #2 and connected-mode is on (CNCT.)
  273.  
  274.      Note: To abort this routine, press the [ON] key and then press
  275. the [ENTER] key.
  276.  
  277. WIREFRAME:
  278.      The WIREFRAME program plots an oblique-perspective view of a wire-frame
  279. model of the surface with Nx vertices in each row and Ny vertices in each
  280. column. It calls SetWindow to set the XRNG and YRNG and uses much the same
  281. technique as Yview. The sampled region is determined by Xleft, Xright, Ynear,
  282. and Yfar.
  283.  
  284. ShapeToShade:
  285.      The ShapeToShade program plots the function as a Phong-shaded
  286. figure viewed from above with a light source from above, that
  287. is, shaded according to the angle the tangent plane makes with the incident
  288. light source. It assumes that the variable DPAR contains sixteen 4x4 GROBS
  289. to serve as the dithering pattern. The dither patterns included are probably
  290. not the best possible: insights along these lines are most welcome. The
  291. variables Xleft, Xright, Yfar, and Ynear determine the inputs sampled.
  292.  
  293. Movie:
  294.      The Movie program plots Ny cross-sections of the function plot
  295. varying the Y-value from Yfar to Ynear. The viewing window is determined
  296. by Xleft, Xright, Zlow, and Zhigh. Having plotted these frames, it calls the 
  297. utility program, uSMOV (utility-show-movie), to play them  back in
  298. repeated sequence. 
  299.  
  300.      Note: To abort this routine in the plotting phase, press the [ON]
  301. key and then press the [ENTER] key.  To end the movie press any key
  302. (e.g. [ENTER]).
  303.  
  304. uSMOV:
  305.      The uSMOV (utility show-movie) program takes an alternating sequence of 
  306. <n> grobs and <n> descriptors (with <2n> on the top of the stack) from the
  307. stack and shows them in sequence, thus producing a movie effect. Stop
  308. the show with any key press but [ON].
  309.  
  310. SSTMovie:
  311.      After stopping Movie or uSMOV, you can use SSTMovie to step through
  312. the sequence of movie frames. To show the next frame, press any key but
  313. [ENTER] or [ON]. Press [ENTER] to quit.
  314.  
  315. PARSURFACE:
  316.      The PARSURFACE routine takes a 3-vector-valued function of two
  317. variables (stored in EQ as a list of three expression in X and Y) and
  318. draws an oblique-view, perspective, 3D plot of a wire-frame model of
  319. the surface determined by the image in 3-space of the graph of this
  320. function, that is, a parametrized surface. 
  321.  
  322.      The function determined by the current equation is sampled in a
  323. grid with Nx samples in each row and Ny samples in each column with
  324. inputs from the region [XXleft,XXright]x[YYlow,YYhigh].  Each sample
  325. is perspective-projected onto the View Screen along the line
  326. connecting the sample and the eye-point (Xe,Ye,Ze).  Neighboring
  327. samples are connected by straight lines. The region of the View Screen
  328. represented in the PICT grob (and hence on the LCD) is determined by
  329. the projection of the View Volume on the View Screen.
  330.  
  331.      A nice starter example is a parametrized sphere. With the triple,
  332. { 'SIN(X)*SIN(Y)' 'COS(X)*SIN(Y)' 'COS(Y)' } stored as EQ, the
  333. view-volume set to [-1.1, 1.1]x[-1.1, 1.1]x[-1.1, 1.1], the eye-point
  334. set to (-2.2, 0, 0.5), and the input range set to [0, 6.5]x[0, 3.15]
  335. (RADIANS MODE, PLEASE!), PARSURFACE will produce a perspective plot
  336. of a sphere.
  337.  
  338. GRIDMAP:
  339.      The GRIDMAP routine takes a complex valued function (stored in EQ
  340. as a complex-valued expression in X and Y) and plots the image under
  341. this map of a rectilinear grid with Nx columns and Ny rows which lives
  342. in the region [XXleft,XXright]x[YYnear,YYfar]. The portion of the
  343. output plane shown on the screen is "floor" of the view-volume,
  344. [Xleft,Xright]x[Ylow,Yhigh]. These are additional variables in VPAR.
  345. The trig and arc-trig functions (e.g. 'SIN(X+i*Y)') give very
  346. interesting "starter" examples.
  347.  
  348.      To get the image of a polar grid rather than a rectilinear grid,
  349. precompose you function with the polar-to-rectangular coordinate
  350. change:
  351.   'SIN(X+i*Y)' {X 'X*COS(Y)' Y 'X*SIN(Y)'} |
  352. => 'SIN(X*COS(Y)+i*X*SIN(Y))'
  353.  
  354.      Setting 'Xleft' to 0 and 'Xright' to 1 then corresponds to
  355. setting (the nonexistent) 'Rlow' to 0 and 'Rhigh' to 1. Similarly,
  356. settign 'Ynear' to 0 and 'Yfar' to 2pi corresponds to setting the
  357. angular range.
  358.  
  359. SetWindow:
  360.     This utility maps the view volume and eye-point coordinates into the
  361. appropriate XRNG and YRNG values for perspective plotting (see the picture
  362. in the YView description.) It also gets all the plotting parameters onto
  363. the stack.
  364.  
  365. _The POSTSCRIPT Drawing Utilities_
  366.  
  367.      Since the PS utilities take up a fair amount of space, and are not of
  368. immediate use to someone without Adobe Illustrator and/or a POSTSCRIPT
  369. printer, all of the above programs have been designed to work properly
  370. even if the PS utility set is not installed. If this is your situation,
  371. simply delete the section of the Suite3D listing starting at the comment, 
  372. @ Begin POSTSCRIPT Stuff @, before you send the file to the '48, otherwise,
  373. read on.
  374.  
  375. When POSTSCRIPT Output Mode is switched on (using PSTOGGLE,) all of the
  376. plotting routines above will, in addition to their normal function, 
  377. accumulate POSTSCRIPT commands corresponding to what they were attempting
  378. to plot on the '48 display. These are saved in a sequence of variables,
  379. PSOUT, PSOUT&, PSOUT&&, etc. Although the output is simply ASCII text
  380. saved as '48 character strings, it is broken up into at-most-4Kbyte
  381. chunks so that it is easier to handle on the '48. When this text is
  382. inserted into a "boilerplate" file (described below) the resulting
  383. file can be sent to a POSTSCRIPT printer, or edited/viewed in the
  384. Adobe Illustrator, or compatible, POSTSCRIPT Drawing program.
  385.  
  386. _Descriptions of the User-intended Programs__
  387.  
  388. PSTOGGLE:
  389.      When executed, this routine switches between normal (no-PS output)
  390. and PS-output definitions of the basic graphics routines (that is, draw,
  391. line, and tile) used in the other Suite3D programs. The new state ("PS is ON"
  392. or "PS is OFF") is displayed on completion of the routine.
  393.  
  394. PSRESET:
  395.     This routine should be used to simply clear any leftover data in the
  396. output variables PSOUT, PSOUT&, etc. making room for a new run.
  397.  
  398. _Using the PS Capabilities_
  399.  
  400.   _The Boilerplate File_
  401.     To effectively use the PS output from the '48 you need to have a
  402. "boilerplate" POSTSCRIPT file in which you can insert your '48 output
  403. (it can even reside on the '48 if you have room .. in this case you
  404. can have your '48 talk directly to a POSTSCRIPT printer ..) The
  405. easiest way to get one is to create a new illustration in Illustrator
  406. with no actual drawing but with the Fill set to NONE, the Line Width
  407. set to, say, .5, and the Line Color set to 100% BLACK.  Save this as a
  408. POSTSCRIPT (i.e. text) file HP48PS.ai or some such name.
  409.  
  410. Open the resulting file with a text editor so you can see what it looks like.
  411. There are two regions of interest. The first is the line near the top of the
  412. file that looks like
  413.  
  414. %%BoundingBox:x1 y1 x2 y2
  415.  
  416. where x1, x2, y1, and y2 are integers. You should change these to
  417.  
  418. %%BoundingBox:0 0 131 64
  419.  
  420. While this is not strictly necessary, it will allow you to include the '48
  421. produced illustration directly in a TeX document an have the size computed
  422. correctly.
  423.  
  424. The next region of interest is  near the end of file and begins with
  425.  
  426. %%Note:
  427.  
  428. and ends with
  429.  
  430. %%Trailer
  431.  
  432. Clear out anything between these two (this is the region where the '48
  433. output will be inserted) and save the resulting file. This will be your
  434. "boilerplate" file.
  435.  
  436.   _Creating the Output_
  437.      This part is quite easy. After you have found a nice view with one of
  438. the graphing utilities (with PS output turned off to speed things up) set the
  439. RES quite high ( #13d RES [ENTER] will do nicely ) and numeric display
  440. format quite small ( 2 FIX [ENTER] seems pretty good ) to save on room, use
  441. PSRESET to clear the variables (if you want to get rid of a previous session)
  442. and PSTOGGLE to activate PS mode. Now re-active the chosen plotting routine
  443. and let it finish.
  444.  
  445. When it is finished, transfer the contents of all the non-empty PSOUT variables
  446. (in ASCII mode, please) in order (PSOUT, PSOUT&, PSOUT&&, etc.) into the region
  447. of the boilerplate file noted above. Save the resulting file under a new name
  448. (to preserve your boilerplate file) and you are ready to send it to a POSTSCRIPT
  449. printer, include it in a TeX, or muck around with it in a POSTSCRIPT drawing
  450. program.
  451.  
  452.   _RAM Requirements, etc._
  453.      The routines require very different amounts of RAM (corresponding directly
  454. with the output size.) A reasonable psContour results in under 4K of output
  455. while a ShapeToShade can result in nearly 40K of output. The other routines
  456. fall between these two (with reasonable settings for Nx, Ny, RES, and FIX.)
  457. If desired, one could modify the PSADDTO routine (see below) to simply send 
  458. accumulated data out over one of the datacomm ports thus passing off the space
  459. requirements to the machine at the other end of the line.
  460.  
  461.   _What's Been Tried_
  462.      I've used the PS output in the form discussed above with equally good
  463. results in Illustrator88 on a Mac IIx, direct printing to an Apple LaserWriter,
  464. in a Textures TeX file, and in Adobe Illustrator 1.1 under  Windows 3.0.
  465.  
  466. POSTSCRIPT, Adobe Illustrator, and Illustrator88 are trademarks of Adobe Systems
  467. Corporation;
  468. Textures is a trademark of Blue Sky Research, Inc.;
  469. Apple LaserWriter is a trademark of Apple Computer, Inc.; 
  470. Windows is a trademark of MicroSoft Corporation;
  471. TeX is a trademark of the American Mathematical Society.
  472.  
  473. _Descriptions of the Utilities_
  474.  
  475. PSTILE:
  476.     This utility takes a screen location (as #pixel_row #pixel_column)
  477. followed by two unused parameters and a gray-scale value in the range [0,1],
  478. returns these unchanged to the stack and outputs the PS code to draw a 
  479. filled-in 4x4 square at the corresponding location and with the corresponding
  480. gray-scale fill.
  481.  
  482. PSADDTO:
  483.    This utility takes a string off the stack and adds it to the current
  484. PS output variable, checking for overflow of the 4000 character limit
  485. and starting a new output variable if the limit is exceeded.
  486.  
  487. PSDRAW:
  488.    Draws the current EQ (assumed to be a single expression) and outputs
  489. a PS representation of the curve drawn as a connected sequence of Bezier
  490. curves. It assumes that the plot type is currently FUNCTION.
  491.  
  492. PSPARDRAW
  493.   Draws the current EQ (assumed to be a single expression) and outputs
  494. a PS representation of the curve drawn as a connected sequence of
  495. Bezier curves. It assumes that the plot type is currently PARAMETRIC.
  496.  
  497. PSLINE:
  498.   Takes a pair of complex numbers representing the endpoints of a line,
  499. draws the line on the screen and outputs the corresponding PS line drawing
  500. command.
  501.  
  502. CURRENTOUT:
  503.   A variable containing the name of the current PS output variable 
  504. ('PSOUT', 'PSOUT&', 'PSOUT&&', etc.)
  505.  
  506. PSCO:
  507.   Takes a complex number and returns, as a string, the corresponding
  508. PS coordinate value.
  509.  
  510. PSCOPAIR:
  511.   Takes a pair of complex numbers representing the third and fourth of
  512. four Bezier curve control points and returns these as a string representing
  513. the PS cross-over sequence of a Bezier curve.
  514.  
  515. derFP
  516.   A definition of the derivative of the FP function suitable for
  517. supporting the PS drawing in GRIDMAP.
  518.  
  519. derIP
  520.   A definition of the derivative of the IP function suitable for
  521. supporting the PS drawing in GRIDMAP.
  522.  
  523. derIM
  524.   A definition of the derivative of the IM function suitable for
  525. supporting the PS drawing in GRIDMAP.
  526.  
  527. derRE
  528.   A definition of the derivative of the RE function suitable for
  529. supporting the PS drawing in GRIDMAP.
  530. END_DOC
  531.  
  532. BEGIN_RPL Suite3D.rpl
  533. %%HP: T(3)A(R)F(.);
  534. DIR
  535.  
  536.   VPAR
  537.   DIR
  538.     Xleft
  539.       0
  540.     Xright
  541.       3
  542.     Ynear
  543.       0
  544.     Yfar
  545.       3
  546.     Zlow
  547.       -1
  548.     Zhigh
  549.       2.5
  550.     XXleft
  551.       0
  552.     XXright
  553.       3
  554.     YYlow
  555.       0
  556.     YYhigh
  557.       3
  558.     Xe
  559.       2.5
  560.     Ye
  561.       -1.5
  562.     Ze
  563.       2
  564.     Nx
  565.       13
  566.     Ny
  567.       8
  568.     Hidden
  569.       0
  570.   END
  571.  
  572.   SlopeField
  573.     \<< {VPAR Nx} RCL
  574.         {VPAR Ny} RCL
  575.         {VPAR Xleft} RCL {VPAR Xright} RCL DUP2  XRNG
  576.         {VPAR Ynear} RCL {VPAR Yfar} RCL DUP2 YRNG
  577.         EQ
  578.         0 0 0 0 0 0 0
  579.     \-> numx numy left right bot top der hstp vstp hofs vofs x y d
  580.       \<< ERASE {# 0d # 0d } PVIEW
  581.           right left - numx / 'hstp' STO
  582.       top bot - numy / 'vstp' STO
  583.       hstp .4 * 'hofs' STO
  584.       vstp .4 * 'vofs' STO
  585.       bot vstp 2 / + top
  586.         FOR y
  587.         y 'Y' STO
  588.         left hstp 2 / +
  589.         right
  590.           FOR x
  591.           x 'X' STO
  592.           der \->NUM  'd' STO
  593.           'IFTE(ABS(d*hofs)>vofs,vofs/d+i*vofs,hofs+i*hofs*d)' \->NUM
  594.           x y R\->C DUP2 + 3 ROLLD SWAP - line
  595.           hstp
  596.           STEP
  597.       vstp
  598.         STEP
  599.       \>>
  600.       { X Y } PURGE { } PVIEW
  601.     \>>
  602.  
  603.   psContour
  604.     \<<         EQ
  605.       \<< \-> dx dy 'IFTE(dy==0,MAXR,-dx/dy)' \>>
  606.       \-> eq slp
  607.       \<<
  608.         IFERR eq X \.d
  609.           eq Y \.d
  610.           2 \->LIST
  611.           'slp' APPLY
  612.           { X Y } SHOW STEQ
  613.           SlopeField
  614.         THEN eq STEQ ERRM DOERR
  615.         END eq STEQ
  616.       \>>
  617.     \>>
  618.  
  619.   YView
  620.     \<< SetWindow 0
  621.       \<< \-> K
  622.         \<<
  623.           CASE
  624.              K TYPE DUP 0 ==
  625.             THEN
  626.              DROP X K R\->C
  627.          X -50 R\->C
  628.          DUP2 LINE TLINE
  629.          K
  630.             END
  631.              1 ==
  632.             THEN K
  633.             END
  634.             K EVAL 1 \->LIST
  635.         'PRASE' APPLY
  636.           END
  637.         \>>
  638.       \>> \-> Xleft Xright Ynear Yfar Xe Ye Ze Nx Ny  prase u hline
  639.       \<< 'EQ' RCL
  640.           'u' \-> eq u
  641.         \<< eq { X '(X-Xe)*u+Xe' Y 'u+Ye' } |
  642.         Ze - 'u' / Ze +
  643.         { X u } SHOW
  644.         COLCT
  645.           IF prase
  646.           THEN { & 'hline(&)' } \|vMATCH DROP
  647.           END
  648.           IFERR
  649.          'EQ' STO 'X' INDEP
  650.          ERASE
  651.          Ynear Yfar - 8 /
  652.          \-> stp
  653.             \<< Yfar Ye -
  654.             Ynear Ye -
  655.               FOR u
  656.               draw
  657.           IF KEY
  658.           THEN DROP
  659.           "outa here" DOERR
  660.           END
  661.           stp
  662.               STEP
  663.             \>>
  664.           THEN eq STEQ ERRM DOERR
  665.           ELSE eq STEQ
  666.           END
  667.       { } PVIEW
  668.         \>>
  669.       \>>
  670.     \>>
  671.  
  672.  
  673.   WIREFRAME
  674.     \<<  SetWindow 0 0 0 0
  675.     \->  Xmin Xmax Ynear Yfar Xe Ye Ze numx numy prase u v bd1 bd2
  676.       \<< 'u' 'v' \-> u v
  677.         \<< EQ { X v Y 'u+Ye' } |
  678.         Ze - 'u' / Ze +
  679.         { v u } SHOW COLCT ERASE
  680.         { # 0d # 0d } PVIEW
  681.         Ynear Yfar - numy /
  682.         Xmax Xmin - numx /
  683.         \-> eq stpu stpx
  684.           \<< Yfar Ye -
  685.           Ynear Ye -
  686.             FOR u
  687.             0 'bd1' STO
  688.         Xmin 'v' STO
  689.         0 numx
  690.               START
  691.             v Xe - u / Xe +
  692.         eq \->NUM R\->C
  693.         IF bd1
  694.         THEN DUP2 line
  695.         ELSE 1 'bd1' STO
  696.         END
  697.         IF bd2
  698.         THEN numx 2 + ROLL OVER line
  699.         END
  700.         stpx 'v' STO+
  701.               NEXT
  702.           1 'bd2' STO
  703.           stpu
  704.             STEP
  705.         numx 1 + DROPN
  706.           \>> { } PVIEW
  707.         \>>
  708.       \>>
  709.     \>>
  710.  
  711.   ShapeToShade
  712.     \<< {VPAR Xleft} RCL
  713.         {VPAR Xright} RCL
  714.         {VPAR Ynear} RCL
  715.         {VPAR Yfar} RCL
  716.     0 0 0 \-> xmin xmax ymin ymax x y eq
  717.       \<< xmax xmin - 32 /
  718.           ymin ymax - 15.001 /
  719.       'x' 'y'
  720.       \-> xstp ystp x y
  721.         \<< EQ DUP
  722.         X \.d .4 - 2 ^ SWAP
  723.         Y \.d .4 + 2 ^ +
  724.         1 + -.35 ^
  725.         { X x Y y } | COLCT
  726.         'eq' STO
  727.         ERASE {# 0d # 0d } PVIEW
  728.         # 0d
  729.         ymax ymin
  730.           FOR y
  731.           # 0d
  732.           xmin xmax
  733.             FOR x
  734.             DUP2 SWAP 2 \->LIST
  735.         PICT SWAP
  736.         eq \->NUM
  737.               IF
  738.             DUP TYPE 0 \=/
  739.               THEN
  740.             DROP 1
  741.               END
  742.               tile
  743.         15.99 * IP
  744.         DPAR SWAP 16 - NEG GET
  745.         REPL
  746.         4 +
  747.         xstp
  748.             STEP
  749.         DROP
  750.         4 +
  751.         ystp
  752.           STEP DROP { } PVIEW
  753.         \>>
  754.       \>>
  755.     \>>
  756.  
  757.   Movie
  758.     \<< {VPAR Xleft} RCL {VPAR Xright} RCL XRNG
  759.         {VPAR Zlow} RCL {VPAR Zhigh} RCL YRNG
  760.         {VPAR Ynear} RCL {VPAR Yfar} RCL
  761.         {VPAR Ny} RCL
  762.         EQ
  763.     0 0
  764.     \->  ynear yfar numy eq ystp y
  765.       \<< 'y' 'y' STO
  766.           eq { X Y } SHOW
  767.       { Y y } |
  768.       ynear yfar - numy / 'ystp' STO
  769.         IFERR STEQ
  770.          'X' INDEP
  771.          FUNCTION
  772.          0 yfar ynear
  773.           FOR y
  774.           ERASE draw
  775.           y PICT RCL ROT 2 +
  776.             IF KEY
  777.             THEN
  778.           DROP "outa here"
  779.           DOERR
  780.             END
  781.         ystp
  782.           STEP
  783.         THEN
  784.          eq STEQ
  785.          ERRM DOERR
  786.         END
  787.     eq STEQ
  788.       \>> uSMOV
  789.     \>>
  790.  
  791.   uSMOV
  792.     \<< \-> n
  793.       \<< { # 0d # 0d } PVIEW
  794.         DO n ROLL
  795.        n ROLL
  796.        DUP PICT {# 0d # 0d } ROT REPL
  797.         UNTIL KEY
  798.         END DROP n
  799.       \>>
  800.     \>>
  801.  
  802.   SSTMovie
  803.     \<<
  804.       DO
  805.         \-> n
  806.         \<< n ROLL n ROLL DUP PICT
  807.         {# 0d # 0d } ROT REPL n
  808.         { # 0d # 0d } PVIEW
  809.         \>>
  810.       UNTIL 0 WAIT
  811.             51.1 ==
  812.       END
  813.     \>>
  814.  
  815.   PARSURFACE
  816.   \<< SetWindow 3 DROPN  EQ
  817.       \-> xe ye ze  eq
  818.       \<< 4 DROPN eq LIST\-> DROP
  819.           SWAP ye - SWAP ze - OVER / ze + 'i' * 
  820.           ROT xe -  ROT /  xe + +
  821.           IFERR
  822.             STEQ
  823.             0 dogridmap
  824.           THEN eq STEQ ERRM DOERR
  825.           ELSE eq STEQ
  826.           END
  827.       \>>
  828.   \>>
  829.  
  830.   GRIDMAP
  831.  \<< 1 dogridmap \>>
  832.  
  833.   dogridmap
  834.   \<< EQ PPAR VPAR XXright XXleft YYlow YYhigh
  835.           Xleft Xright Ynear Yfar Nx Ny
  836.       UPDIR 
  837.       \-> setrng eq pp X1 X2 Y1 Y2 xr1 xr2 yr1 yr2 NX NY
  838.     \<< X2 X1 - 
  839.         Y2 Y1 -
  840.         \-> DX DY
  841.       \<< eq { X 
  842.                'X1+DX*(1+INV(NX-1))*
  843.                (.5+(-1)^IP(NY*((1-INV(NX*NY))*TTT+.5/(NX*NY)))*
  844.                (-.5+FP(NY*((1-INV(NX*NY))*TTT+.5/(NX*NY)))))-
  845.                .5*(DX/(NX-1))' 
  846.                Y 
  847.                'Y1+DY/(NY-1)*IP(NY*((1-INV(NX*NY))*TTT+.5/(NX*NY)))'
  848.               } | { TTT } SHOW 
  849.            eq { X 
  850.                'X1+DX/(NX-1)*IP(NX*((1-INV(NY*NX))*TTT+.5/(NY*NX)))' 
  851.                Y 
  852.                'Y1+DY*(1+INV(NY-1))*
  853.                (.5+(-1)^IP(NX*((1-INV(NY*NX))*TTT+.5/(NY*NX)))*
  854.                (-.5+FP(NX*((1-INV(NY*NX))*TTT+.5/(NY*NX)))))-
  855.                .5*(DY/(NY-1))'
  856.                } | { TTT } SHOW 
  857.           SWAP
  858.         IFERR { TTT 0 1 } INDEP
  859.               PARAMETRIC 
  860.               IF setrng
  861.               THEN
  862.               xr1 xr2 XRNG 
  863.               yr1 yr2 YRNG
  864.               END
  865.               NX NY * 1 - INV RES
  866.               STEQ 
  867.               ERASE pardraw
  868.               STEQ pardraw 
  869.               { } PVIEW 
  870.               pp 'PPAR' STO eq STEQ
  871.         THEN eq STEQ pp 'PPAR' STO 
  872.               ERRM DOERR
  873.         END
  874.       \>>
  875.     \>>
  876.   \>>
  877.  
  878.   DPAR {
  879. GROB 4 4 00400000
  880. GROB 4 4 00402000
  881. GROB 4 4 90000080
  882. GROB 4 4 40104010
  883. GROB 4 4 20802090
  884. GROB 4 4 8050A010
  885. GROB 4 4 50A05080
  886. GROB 4 4 A050A050
  887. GROB 4 4 50A050A0
  888. GROB 4 4 A050A070
  889. GROB 4 4 70A050E0
  890. GROB 4 4 D070D060
  891. GROB 4 4 B0E0B0E0
  892. GROB 4 4 70D0F0B0
  893. GROB 4 4 F0B0D0F0
  894. GROB 4 4 F0B0F0F0 }
  895.  
  896.   EQ
  897.     '2*(2-Y)*EXP(-((X-.5)^2+(Y-1.2)^2))+Y*EXP(-2*((X-2)^2+(Y-2)^2))'
  898.  
  899.   PPAR
  900.     { (-2,0) (2,5) X # 8d (0,0) FUNCTION Y }
  901.  
  902.   SetWindow
  903.     \<< PATH
  904.         VPAR
  905.         Xleft Xright Ynear Yfar Zlow Zhigh Xe Ye Ze Nx Ny Hidden 0
  906.        \-> Xleft Xright Ynear Yfar Zlow Zhigh Xe Ye Ze Nx Ny Hidden Ue
  907.        \<< EVAL
  908.            \<< \-> u y '(u-Ue)/(y-Ye)+Ue' SWAP OVER MAX ROT ROT MIN SWAP \>>
  909.            \-> proj
  910.            \<< Xe 'Ue' STO
  911.                MAXR \->NUM DUP NEG
  912.                Xleft Ynear proj EVAL
  913.                Xleft Yfar proj EVAL
  914.                Xright Ynear proj EVAL
  915.                Xright Yfar proj EVAL
  916.                XRNG
  917.                Ze 'Ue' STO
  918.                MAXR \->NUM DUP NEG
  919.                Zlow Ynear proj EVAL
  920.                Zlow Yfar proj EVAL
  921.                Zhigh Ynear proj EVAL
  922.                Zhigh Yfar proj EVAL
  923.                YRNG
  924.            \>>
  925.            Xleft Xright Ynear Yfar Xe Ye Ze Nx Ny Hidden
  926.       \>>
  927.    \>>
  928.  
  929.  
  930.   draw
  931.     DRAW
  932.  
  933.   line
  934.     LINE
  935.  
  936.   tile
  937.    \<< \>>
  938.  
  939.   pardraw
  940.     DRAW
  941.  
  942. @ Begin POSTSCRIPT Stuff @
  943.  
  944.   PSTOGGLE
  945.    \<< "PS is "
  946.      IF 'draw' RCL 'PSDRAW' SAME
  947.      THEN { DRAW } 1    GET DUP 'draw' STO
  948.           'pardraw' STO 
  949.           { LINE } 1 GET 'line'    STO
  950.           \<<  \>> 'tile' STO
  951.          "Off" +
  952.      ELSE 'PSDRAW' 'draw' STO 
  953.           'PSLINE'  'line' STO 
  954.           'PSTILE'  'tile' STO
  955.           'PSPARDRAW'  'pardraw' STO 
  956.           "On" +
  957.      END 1 DISP
  958.    \>>
  959.    
  960.   PSRESET
  961.     \<< "'PSOUT" 'PSOUT'
  962.         DO "" SWAP STO
  963.        "&" + DUP STR\-> DUP
  964.     UNTIL VTYPE -1 ==
  965.     END
  966.     DROP2 'PSOUT' 'CURRENTOUT' STO
  967.     \>>
  968.  
  969.   PSTILE
  970.     \<< DUP \->STR
  971.         " g
  972. "
  973.       + 5 PICK B\->R
  974.     DUP 4 + \->STR " " +
  975.     SWAP \->STR " " +
  976.     8 PICK # 64d SWAP - B\->R
  977.     DUP 4 - \->STR
  978.     " " + SWAP \->STR " " +
  979.     \-> X2 X1 Y1 Y2
  980.       \<< X2 + Y1 +
  981. "m
  982. "
  983.       + X2 + Y2 +
  984. "L
  985. "
  986.       + X1 + Y2 +
  987. "L
  988. "
  989.       + X1 + Y1 +
  990. "L
  991. "
  992.       + X2 + Y1 +
  993. "L
  994. f
  995. "
  996.       +
  997.       \>> PSADDTO
  998.     \>>
  999.  
  1000.   PSADDTO
  1001.     \<<
  1002.       IF CURRENTOUT SIZE 4000 >
  1003.       THEN 'CURRENTOUT' RCL \->STR
  1004.            1 OVER SIZE 1 - SUB "&" + STR\->
  1005.        DUP 'CURRENTOUT' STO STO
  1006.       ELSE
  1007.            'CURRENTOUT' RCL SWAP STO+
  1008.       END
  1009.     \>>
  1010.  
  1011.   CURRENTOUT
  1012.     PSOUT
  1013.  
  1014.   PSCOPAIR
  1015.     \<< 'PPAR(1)' EVAL DUP
  1016.         'PPAR(2)' EVAL SWAP -
  1017.     \-> p1 p2 o d
  1018.       \<< p2 o - C\->R
  1019.           d C\->R ROT SWAP / 64 *
  1020.       ROT ROT / 131 *
  1021.       p1 o - C\->R d C\->R
  1022.       ROT SWAP / 64 *
  1023.       ROT ROT / 131 *
  1024.       \>> \-> y2 x2 y1 x1
  1025.       \<< x1 \->STR " " +
  1026.           y1 \->STR " " + +
  1027.       x2 \->STR " " + +
  1028.       y2 \->STR " " + +
  1029.       x2 x1 - x2 + \->STR " " +
  1030.       y2 y1 - y2 + \->STR " " + +
  1031.       \>>
  1032.     \>>
  1033.  
  1034.   PSDRAW
  1035.     \<< PPAR OBJ\-> 4 DROPN
  1036.         0 0
  1037.     \-> hm vm indp rs flop \Gdx
  1038.       \<<
  1039.         IF rs TYPE 10 ==
  1040.         THEN rs # 0d 2 \->LIST PX\->C hm - RE
  1041.         ELSE
  1042.           IF rs 0 ==
  1043.           THEN { # 1d # 0d } PX\->C hm - RE
  1044.           ELSE rs
  1045.           END
  1046.         END
  1047.     3 / '\Gdx' STO
  1048.     'EQ' RCL 'vm' STO
  1049.         \<< \-> vl
  1050.           \<< vl \->NUM
  1051.           indp \->NUM
  1052.           \-> vlu indv
  1053.             \<<
  1054.               IF flop
  1055.               THEN indv \Gdx - vl indp \.d \->NUM
  1056.                \Gdx *
  1057.            vlu SWAP - R\->C
  1058.            'indp+vl*i' \->NUM PSCOPAIR
  1059.            3 ROLLD + "c
  1060. "
  1061.                +
  1062.            PSADDTO
  1063.               ELSE
  1064.                'indp+vl*i' \->NUM
  1065.            PSCO "m
  1066. "
  1067.                    +
  1068.            indv \Gdx +
  1069.            vl indp \.d \->NUM
  1070.            \Gdx * vlu + R\->C PSCO +
  1071.            1 'flop' STO
  1072.               END
  1073.           vlu
  1074.             \>>
  1075.           \>>
  1076.         \>> 'hm' STO
  1077.         IFERR vm {& 'hm(QUOTE(&))' } \|vMATCH DROP STEQ
  1078.           DRAW vm STEQ
  1079.         THEN vm STEQ ERRM DOERR
  1080.         END "S
  1081. "
  1082.         PSADDTO
  1083.       \>>
  1084.     \>>
  1085.  
  1086.   PSPARDRAW
  1087.     \<< 'PPAR(3)' EVAL OBJ\-> DROP 'PPAR(4)' EVAL 0 0
  1088.         \-> indp hm vm rs flop \Gdx
  1089.       \<<
  1090.         IF rs 0 ==
  1091.         THEN # 1d 'rs' STO
  1092.         END
  1093.         IF rs TYPE 10 ==
  1094.         THEN rs B\->R 131 / vm hm - *
  1095.         ELSE rs
  1096.         END 3 / '\Gdx' STO 'EQ' RCL 'vm' STO
  1097.         \<< \-> vl
  1098.           \<< vl \->NUM indp \->NUM
  1099.               \-> vlu indv
  1100.             \<<
  1101.               IF flop
  1102.               THEN vl indp \.d \->NUM \Gdx * vlu SWAP - (0,0) + vlu (0,0) +
  1103.                    PSCOPAIR 3 ROLLD +
  1104. "c
  1105. "                  + PSADDTO
  1106.               ELSE vlu (0,0) + PSCO
  1107. "m
  1108. "
  1109.                    + vl indp \.d \->NUM \Gdx * vlu + (0,0) + PSCO +
  1110.                     1 'flop' STO
  1111.               END
  1112.               vlu
  1113.             \>>
  1114.           \>>
  1115.         \>> 'hm' STO
  1116.         IFERR vm { & 'hm(QUOTE(&))' } \|vMATCH DROP STEQ
  1117.               DRAW vm STEQ
  1118.         THEN vm STEQ ERRM DOERR
  1119.         END
  1120. "S
  1121. "
  1122.         PSADDTO
  1123.       \>>
  1124.     \>>
  1125.  
  1126.   PSCO
  1127.     \<< 'PPAR(1)' EVAL - C\->R
  1128.         'PPAR(2)-PPAR(1)' EVAL C\->R
  1129.     ROT SWAP / 64 *
  1130.     ROT ROT / 131 * \->STR
  1131.     " " + SWAP \->STR
  1132.     " " + +
  1133.     \>>
  1134.  
  1135.   PSLINE
  1136.     \<< \-> C1 C2
  1137.       \<< C1 PSCO
  1138. "m
  1139. "
  1140.           + C2 PSCO +
  1141. "l
  1142. S
  1143. "
  1144.           + PSADDTO
  1145.       C1 C2 LINE
  1146.       \>>
  1147.     \>>
  1148.  
  1149.   derFP
  1150.     \<< \-> K DK 'DK'    \>>
  1151.   derIP
  1152.     \<< \-> K DK '0'   \>>
  1153.   derIM
  1154.     \<< \-> K DK 'IM(DK)'   \>>
  1155.   derRE
  1156.     \<< \-> K DK 'RE(DK)'   \>>
  1157.  
  1158.   PSOUT
  1159.    ""
  1160.   PSOUT&
  1161.    ""
  1162.   PSOUT&&
  1163.    ""
  1164.   PSOUT&&&
  1165.    ""
  1166.   PSOUT&&&&
  1167.    ""
  1168.   PSOUT&&&&&
  1169.    ""
  1170.   PSOUT&&&&&&
  1171.    ""
  1172. END
  1173. END_RPL
  1174.