home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 8 / CDASC08.ISO / VRAC / SEP93CAD.ZIP / GORE.LSP < prev    next >
Lisp/Scheme  |  1993-08-31  |  6KB  |  218 lines

  1. ;==========================================================
  2. ; GORE.LSP Copyright 1993 by Looking Glass Microproducts
  3. ;==========================================================
  4. ; Draws a gore 
  5. ;=============================================================
  6. (defun ASIN (X) (atan X (sqrt (- 1.0 (* X X )))))
  7.  
  8. (defun C:GORE (/ ERROR PUSHVARS POPVARS SYSVARS OLD-ERROR NOTRANS
  9.                XGETINT XGETKWORD GETPARMS <-90 <90 <180)
  10.    (setq <-90 (* -0.5 pi) <90 (* 0.5 pi) <180 pi)
  11.    ;==========================================================
  12.    ; Error Handler
  13.    (defun ERROR (S)
  14.       (if (not
  15.              (member
  16.                 S
  17.                 '("Function cancelled" "console break")
  18.              )
  19.           )
  20.          (alert S)
  21.       )
  22.       (command ".undo" "end")
  23.       (command ".undo" "1")
  24.       (POPVARS)
  25.       (princ)
  26.    )
  27.    ;==========================================================
  28.    ; Set and Save System Variables
  29.    (defun PUSHVARS (VLIST)
  30.       (foreach PAIR VLIST
  31.          (setq
  32.             SYSVARS (cons
  33.                        (cons
  34.                           (strcase (car PAIR))
  35.                           (getvar
  36.                              (car PAIR)
  37.                           )
  38.                        )
  39.                        SYSVARS
  40.                     )
  41.          )
  42.          (if (cdr PAIR) (setvar (car PAIR) (cdr PAIR)))
  43.       )
  44.    )
  45.    ;==========================================================
  46.    ; Restore System Variables
  47.    (defun POPVARS ()
  48.       (foreach PAIR SYSVARS (setvar (car PAIR) (cdr PAIR)))
  49.       (setq
  50.          *error* OLD-ERROR
  51.       )
  52.       (setq SYSVARS nil)
  53.    )
  54.    ;==========================================================
  55.    ; Disallow transparent invocation of routine.
  56.    (defun NOTRANS ()
  57.       (cond
  58.          ((zerop (logand (getvar "cmdactive") (+ 1 2 4 8))))
  59.          ((alert
  60.              "This command may not be invoked transparently."
  61.           )
  62.          )
  63.       )
  64.    )
  65.    ;==========================================================
  66.    ; Get Integer with default
  67.    ;==========================================================
  68.    (defun XGETINT (PRMPT DEFAULT)
  69.       (cond
  70.          ((getint (strcat PRMPT " <" (itoa DEFAULT) ">: ")))
  71.          (DEFAULT
  72.          )
  73.       )
  74.    )
  75.  
  76.    ;==========================================================
  77.    ; GetKword with Default
  78.    ;==========================================================
  79.    (defun XGETKWORD (PRMPT DEFAULT)
  80.       (cond
  81.          ((getkword (strcat PRMPT " <" DEFAULT ">: ")))
  82.          (DEFAULT
  83.          )
  84.       )
  85.    )
  86.  
  87.    ;==========================================================
  88.    ; Main routine
  89.    ;==========================================================
  90.    (defun GETPARMS (/ N-MIN N-DEF)
  91.       (initget 1)
  92.       (setq P0 (getpoint "\nCenter of gore: "))
  93.       (initget "S H")
  94.       (setq
  95.          MODE (XGETKWORD
  96.                  "\nSpherical or Hemispherical gore (S/H)"
  97.                  "S"
  98.               )
  99.       )
  100.       (initget 1 "Diameter")
  101.       (setq
  102.          R (getdist "\nDiameter/<radius>: ")
  103.       )
  104.       (if (= "Diameter" R)
  105.          (progn
  106.             (initget 1)
  107.             (setq
  108.                R (* 0.5 (getdist "\nDiameter: "))
  109.             )
  110.          )
  111.       )
  112.       (while (progn
  113.                 (initget 6) ; disallow negative, zero       
  114.                 (setq
  115.                    M (XGETINT
  116.                         "\nNumber of longitudinal segments"
  117.                         16
  118.                      )
  119.                 )
  120.                 (< M 3)
  121.              )
  122.          (prompt
  123.             "\nNumber of segments must be at least 3."
  124.          )
  125.       )
  126.       (if (= MODE "S")
  127.          (setq N-MIN 2 N-DEF 16)
  128.          (setq N-MIN 1 N-DEF 8)
  129.       )
  130.       (while (progn
  131.                 (initget 6) ; disallow negative, zero       
  132.                 (setq
  133.                    N (XGETINT
  134.                         "\nNumber of latitudinal segments"
  135.                         N-DEF
  136.                      )
  137.                 )
  138.                 (< N N-MIN)
  139.              )
  140.          (prompt
  141.             (strcat
  142.                "\nNumber of segments must be at least "
  143.                (itoa
  144.                   N-MIN
  145.                )
  146.                "."
  147.             )
  148.          )
  149.       )
  150.    )
  151.    ;==========================================================
  152.    ; Main routine
  153.    ;==========================================================
  154.    (defun GORE (/ P0 MODE R M N SINB A DA TOP BOT)
  155.       (GETPARMS)
  156.       (setq SINB (sin (/ <180 M)))
  157.       (if (= MODE "S")
  158.          (setq A <-90 DA (/ <180 N))
  159.          (setq A 0.0 DA (/ <90 N))
  160.       )
  161.       (repeat
  162.          (1+ N)
  163.          (setq
  164.             X   (* R A)
  165.             Y   (* R (ASIN (* (cos A) SINB)))
  166.             TOP (cons (list X Y) TOP)
  167.             BOT (cons (list X (- Y)) BOT)
  168.             A   (+ A DA)
  169.          )
  170.       )
  171.       (setq
  172.          POINTS (append
  173.                    TOP
  174.                    (if (= MODE "S")
  175.                       (cdr (reverse (cdr BOT)))
  176.                       (reverse
  177.                          (cdr BOT)
  178.                       )
  179.                    )
  180.                    (list "c")
  181.                 )
  182.       )
  183.       (setvar "blipmode" 0)
  184.       (command ".ucs" "or" P0)
  185.       (command ".pline")
  186.       (apply 'command POINTS)
  187.       (command ".ucs" "p")
  188.       (setvar "lastpoint" P0)
  189.    )
  190.    ;==========================================================
  191.    ; Body of c:gore  
  192.    ;==========================================================
  193.    (if (NOTRANS)
  194.       (progn
  195.          (setq OLD-ERROR *error* *error* ERROR)
  196.          (setvar
  197.             "cmdecho" 0
  198.          )
  199.          (command ".undo" "group")
  200.          (PUSHVARS
  201.             '(("osmode" . 0) ("plinewid" . 0) ("blipmode"))
  202.          )
  203.          (GORE)
  204.          (command ".undo" "end")
  205.          (POPVARS)
  206.       )
  207.    )
  208.    (princ)
  209. )
  210. (princ
  211.    (strcat
  212.       "  GORE.LSP (Copyright 1993 by"
  213.       " Looking Glass Microproducts) loaded."
  214.    )
  215. )
  216. (princ)
  217.  
  218.