home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 13 / 13.iso / p / p024 / 11.img / BONUS2.LIB / FPLOT.LSP < prev    next >
Encoding:
Text File  |  1993-01-23  |  4.8 KB  |  139 lines

  1. ;;; --------------------------------------------------------------------------;
  2. ;;;  FPLOT.LSP
  3. ;;;   (C) ¬⌐┼v 1988-1992  Autodesk ñ╜Ñq
  4. ;;;
  5. ;;;   Ñ╗╡{ªíñwÑ╤ Autodesk ñ╜Ñq╡∙ÑU¬⌐┼v, ╢╚⌐≤ñU¡z▒í¬pñUÑi▒┬╗P▒zíu│\ÑiívíC
  6. ;;;   ╗╒ñUñú▒oÑHÑ⌠ª≤º╬ªí╡oªµ⌐╬ÑX¬⌐ª╣╡{ªí¬║íu¡∞⌐l╜Xív; ª²ñ╣│\▒zªb»S⌐w¡lÑ═
  7. ;;;   ¬║ñuº@ñW╡▓ªXª╣╡{ªí¬║íuÑ╪¬║╜Xív¿╧Ñ╬íCª│├÷│o├■¡lÑ═ñuº@¬║▒°Ñ≤ªpñU:
  8. ;;;
  9. ;;;   ( i)  │]¡pñW╗Pñuº@ñW¼╥»┬║Θ░w╣∩ Autodesk ñ╜Ñq¬║▓ú½~íC
  10. ;;;   (ii)  ╕ⁿª│íu¬⌐┼v  (C) 1988-1992  Autodesk ñ╜Ñqív¬║¬⌐┼v│qºiíC
  11. ;;;
  12. ;;;
  13. ;;;
  14. ;;;   AUTODESKñ╜Ñq┤ú¿╤ª╣╡{ªí╢╚¿╤º@íu├■ªⁿív¬║░╤ª╥, ª╙ÑBñú▒╞░úª│Ñ⌠ª≤┐∙╗~¬║
  15. ;;;   Ñi»αíCAUTODESKñ╜Ñq»Sª╣º_╗{Ñ⌠ª≤»S⌐wÑ╬│~ñº╛A║┘⌐╩, ÑHñ╬░╙╖~╛P░Γ⌐╥┴⌠ºt
  16. ;;;   ÑX¿π¬║½O├╥íCAUTODESKñ╜ÑqªP«╔ÑτñúÑX¿πª╣╡{ªí░⌡ªµ«╔ñ@⌐wñú╖|íuññ┬_ív⌐╬
  17. ;;;   íuº╣Ñ■╡L╗~ív¬║½O├╥íC
  18. ;;;
  19. ;;;
  20. ;;;   Designed and implemented by Kelvin R. Throop in June of 1988
  21. ;;;
  22. ;;; --------------------------------------------------------------------------;
  23. ;;; DESCRIPTION
  24. ;;;   Plot function of two variables
  25. ;;;
  26. ;;;   To make a three dimensional polygon mesh representing the
  27. ;;;   values of a function in two variables across a specified range
  28. ;;;   of values for the two variables, with a defined resolution
  29. ;;;   (specified as the number of subdivisions within the range), call:
  30. ;;;
  31. ;;;   (fplot function xrange yrange resolution)
  32. ;;;
  33. ;;;   where:
  34. ;;;
  35. ;;;   function     The function to be evaluated.  This will
  36. ;;;                usually be the quoted name of a previously-
  37. ;;;                defined function, or a quoted lambda-definition
  38. ;;;                of a function.
  39. ;;;
  40. ;;;   xrange       The range of X values, specified as a list
  41. ;;;                with the first element the lower bound for X
  42. ;;;                and the second element the upper bound.
  43. ;;;
  44. ;;;   yrange       The range of Y values, specified as a list
  45. ;;;                with the first element the lower bound for Y
  46. ;;;                and the second element the upper bound.
  47. ;;;
  48. ;;;   resolution   An integer specifying the granularity of the
  49. ;;;                mesh approximating the surface defined by the
  50. ;;;                function's values for arguments in the specified
  51. ;;;                range.
  52. ;;;
  53. ;;;   For example, to plot (e**(-(X**2 + Y**2))) over the range from
  54. ;;;   -1 to 1 in both the X and Y axes, use:
  55. ;;;
  56. ;;;   (fplot '(lambda (x y) (exp (- (+ (* x x) (* y y)))))
  57. ;;;          '(-2 2)
  58. ;;;          '(-2 2)
  59. ;;;          20
  60. ;;;          )
  61. ;;;
  62. ;;;   (This will look like a tennis ball under the rug, when viewed
  63. ;;;   from, say, VPOINT 1,1,1.)
  64. ;;;
  65. ;;;   Or, you can plot a predefined function.  For example:
  66. ;;;
  67. ;;;             (defun cs (x y)
  68. ;;;               (cos (sqrt (+ (* x x 2) (* y y))))
  69. ;;;             )
  70. ;;;             (fplot 'cs '(-20 20) '(-20 20) 40)
  71. ;;;
  72. ;;;   This makes a series of elliptical ripples, like a pond after
  73. ;;;   you've just dropped in a cinder block.
  74. ;;;
  75. ;;;   This file contains a complex predefined test case.  If you
  76. ;;;   enter the command:
  77. ;;;
  78. ;;;            DEMO
  79. ;;;
  80. ;;;   you'll get the interference pattern from two exponentially
  81. ;;;   damped cosine waves.  This example illustrates the amazing
  82. ;;;   surfaces you can generate with a simple definition using
  83. ;;;   fplot.
  84. ;;;
  85. ;;; --------------------------------------------------------------------------;
  86.  
  87. (defun fplot (fcn xrange yrange res / ce stepx stepy i j x y)
  88.   (setq x (car xrange)
  89.         stepx (/ (- (cadr xrange) x) (float res))
  90.         stepy (/ (- (cadr yrange) (car yrange)) (float res))
  91.         i 0
  92.    res (1+ res)
  93.   )
  94.   (setq ce (getvar "cmdecho"))
  95.   (setvar "cmdecho" 0)
  96.   (command "_.3DMESH" res res)
  97.   (while (< i res)
  98.     (setq j 0
  99.           y (car yrange))
  100.     (while (< j res)
  101.       (command (list x y (apply fcn (list x y))))
  102.       (setq j (1+ j)
  103.             y (+ y stepy))
  104.     )
  105.     (setq i (1+ i)
  106.           x (+ x stepx))
  107.   )
  108.   (setvar "cmdecho" ce)
  109. )
  110.  
  111. ;;;       Demo program
  112. ;;;       Generate exponentially damped cosine wave
  113.  
  114. (defun dampcos (x y / dist omag sfreq decfr)
  115.   (setq omag 2.0                      ; Overall magnitude scale factor
  116.         sfreq 8.0                     ; Spatial frequency factor
  117.         decfr 1.5                     ; Exponential decay spatial frequency
  118.   )
  119.   (setq dist (sqrt (+ (* x x) (* y y))))
  120.   (* omag (cos (* dist sfreq)) (exp (- (* decfr dist))))
  121. )
  122.  
  123. ;;;       Calculate interference of two damped cosine waves
  124.  
  125. (defun interf (x y / offset)
  126.   (setq offset 0.9)                   ; Offset of centres from origin
  127.   (+ (dampcos (- x offset) y) (dampcos (+ x offset) y))
  128. )
  129.  
  130. ;;;       Demo run of function plot, type DEMO at command prompt
  131.  
  132. (defun C:demo ()
  133.   (fplot 'interf'(-3 3) '(-3 3) 50)
  134.   (princ)                             ; Suppress printing function result
  135. )
  136.  
  137. ;;; --------------------------------------------------------------------------;
  138.  
  139.