![]() |
|
Lisp »Tips 'n Tricks »Spirale 3D
A.Dudek
(defun myerror (s)
(if (/= s "Function cancelled")
(princ (strcat "\nError: " s))
)
(setvar "cmdecho" ocmd)
(setvar "blipmode" oblp)
(setq *error* olderr)
(princ)
)
(defun cspiral (ntimes bpoint hfac lppass strad vfac
/ ang dist tp ainc dhinc dvinc circle dv)
(setvar "blipmode" 0)
(setvar "cmdecho" 0)
(setq circle (* 3.141596235 2))
(setq ainc (/ circle lppass))
(setq dhinc (/ hfac lppass))
(if vfac (setq dvinc (/ vfac lppass)))
(setq ang 0.0)
(if vfac
(setq dist strad dv 0.0)
(setq dist 0.0)
)
(if vfac
(command "_3dpoly")
(command "_pline" bpoint)
)
(repeat ntimes
;;;
;;; section of revised code
(if (= ntimes 1) ; if the number of
;rotations is 1
(repeat (1+ lppass) ; then calculate points
; one extra time to allow
; for the missing polyline segment
; at the end of the rotation
(setq tp (polar bpoint (setq ang (+ ang ainc))
(setq dist (+ dist dhinc))
)
)
(if vfac
(setq tp
(list
(car tp)
(cadr tp)
(+ dv (caddr tp))
)
dv (+ dv dvinc)
)
)
(command tp) ; continue to the next point...
);close inner repeat
;;;
;otherwise
(repeat lppass
(setq tp (polar bpoint (setq ang (+ ang ainc))
(setq dist (+ dist dhinc))
)
)
(if vfac
(setq tp
(list
(car tp)
(cadr tp)
(+ dv (caddr tp))
)
dv (+ dv dvinc)
)
)
(command tp) ; continue to the next point...
);close inner repeat
);close if
);close main repeat
(command "") ; until done.
(princ)
);close defun
;;;
;;; Interactive spiral generation
;;;
(defun C:SPIRAL (/ olderr ocmd oblp nt bp cf lp)
(command ".undo" "group")
(setq olderr *error*
*error* myerror)
(setq ocmd (getvar "cmdecho"))
(setq oblp (getvar "blipmode"))
(setvar "cmdecho" 0)
(initget 1) ; bp must not be null
(setq bp (getpoint "\nCenter point: "))
(initget 7) ; nt must not be zero, neg, or null
(setq nt (getint "\nNumber of rotations: "))
(initget 3) ; cf must not be zero, or null
(setq cf (getdist "\nGrowth per rotation: "))
(initget 6) ; lp must not be zero or neg
(setq lp (getint "\nPoints per rotation <30>: "))
(cond ((null lp) (setq lp 30)))
(cspiral nt bp cf lp nil nil)
(setvar "cmdecho" ocmd)
(setvar "blipmode" oblp)
(setq *error* olderr) ; Restore old *error* handler
(princ)
(command ".undo" "end")
)
;;;
;;; Interactive spiral generation
;;;
(defun C:3DSPIRAL (/ olderr ocmd oblp nt bp hg vg sr lp)
(command ".undo" "group")
(setq olderr *error*
*error* myerror)
(setq ocmd (getvar "cmdecho"))
(setq oblp (getvar "blipmode"))
(setvar "cmdecho" 0)
(initget 1) ; bp must not be null
(setq bp (getpoint "\nCenter point: "))
(initget 7) ; nt must not be zero, neg, or null
(setq nt (getint "\nNumber of rotations: "))
(initget 7) ; sr must not be zero, neg, or null
(setq sr (getdist bp "\nStarting radius: "))
(initget 1) ; cf must not be zero, or null
(setq hg (getdist "\nHorizontal growth per rotation: "))
(initget 3) ; cf must not be zero, or null
(setq vg (getdist "\nVertical growth per rotation: "))
(initget 6) ; lp must not be zero or neg
(setq lp (getint "\nPoints per rotation <30>: "))
(cond ((null lp) (setq lp 30)))
(cspiral nt bp hg lp sr vg)
(setvar "cmdecho" ocmd)
(setvar "blipmode" oblp)
(setq *error* olderr)
(princ)
(command ".undo" "end")
)
(defun C:3s ()
(C:3dspiral))
;;;
(princ "\n\tC:SPIRAL and C:3DSPIRAL loaded. ")
(princ "\n\tStart 3DSPIRAL command with 3S")
(princ)
|