How can I plot a Sin(x) curve in AutoCAD with AutoLISP ?
(setq rep 1000 inc (/ (* pi 2) rep) i 0) (command "_PLINE") (repeat rep (command (list i (sin i))) (setq i (+ i inc))) (command "") Adust the variable rep for smoothness. -David
Cheers - That will come in handy / STUPID QUESTION ALERT / Why is the lisp function for tan called atan?
Why is the lisp function for tan called atan? In a right trianlge with: Adjacent = 2 Opposte = 2 (/ 2 2) = 1 = tangent (atan 2 2 ) = 0.785398 = 45d Bill
lisp only have 3 trigonometrics function defined For a rectangle triangle given a= hypothenuse b= cathet oposited to angle x c= cathet adyacent to angle x sin x = b/ a cos x = c /a atan ( b/c) = x all angles in radians with this 3 function you can resolve all trig problems
Here's a bunch of trig functions by Jon Fleming from the old Compuserve days that I still use regularly. -David ;;; The trigonometric functions not included with AutoLISP. ;;; Jon Fleming, May 20 1997. ;;; Note that some of the functions (arcsecant and arccosecant) ;;; use other functions defined in this file. ;;; Note that none of these functions check for valid ;;; arguments. Passing valid arguments is the responsibility ;;; of the calling program. ;;; 9.7E307 was determined experimentally to be the largest ;;; number that can be generated in AutoLISP (in R14). ;;;-------------------------------------------------------- ;;; tangent accepts any angle in radians, and returns the ;;; tangent in the range -9.7E307+epsilon to 9.7E307 inclusive (defun tan (z / cosz) (if (zerop (setq cosz (cos z))) 9.7e307 (/ (sin z) cosz) ) ;_ end if ) ;_ end defun ;;; secant accepts any angle in radians, and returns the ;;; secant in the ranges -9.7E307+epsilon to -1.0 inclusive ;;; and 1.0 to 9.7E307 inclusive (defun sec (z / cosz) (if (zerop (setq cosz (cos z))) 9.7E307 (/ 1.0 cosz) ) ;_ end if ) ;_ end defun ;;; cosecant accepts any angle in radians, and returns the ;;; cosecant in the ranges -9.7E307+epsilon to -1.0 inclusive ;;; and 1.0 to 9.7E307 inclusive (defun csc (z / sinz) (if (zerop (setq sinz (sin z))) 9.7E307 (/ 1.0 sinz) ) ) ;;; arcsine (inverse sine) accepts an argument in the range ;;; -1.0 to 1.0 inclusive, and returns an angle in radians in ;;; the range (-pi/2) to (pi/2) inclusive. (defun asin (z /) (atan z (sqrt (- 1.0 (* z z)))) ) ;_ end defun ;;; arccosine (inverse cosine) accepts an argument in the ;;; range -1.0 to 1.0 inclusive, and returns an angle in ;;; radians in the range pi to 0 inclusive (defun acos (z /) (atan (sqrt (- 1.0 (* z z))) z) ) ;_ end defun ;;; arcsecant (inverse secant) accepts an argument in ;;; one of two ranges: minus infinity to -1 inclusive or ;;; 1 to infinity inclusive, and returns an angle in ;;; radians in the range pi to 0 inclusive (except ;;; EXACTLY pi/2 will never be returned on a computer ;;; with finite numerical precision) (defun asec (z /) (acos (/ 1.0 z)) ) ;_ end defun ;;; arccosecant (inverse cosecant) accepts an argument ;;; in one of two ranges: minus infinity to -1 inclusive or ;;; 1 to infinity inclusive, and returns an angle in ;;; radians in the range -pi/2 to pi/2 inclusive (except ;;; EXACTLY 0.0 will never be returned on a computer ;;; with finite numerical precision) (defun acsc (z /) (asin (/ 1.0 z)) ) ;_ end defun ;;; arccotangent (inverse cotangent) accepts an argument ;;; in the range minus infinity to plus infinity ;;; inclusive and returns an angle in radians in the ;;; range pi to 0 inclusive. (defun acot (z /) (- (/ pi 2.0) (atan z)) ) ;_ end defun (prin1)
See "SNS" option at http://www.btlsp2000.com/REC.LSP. Frequency and amplitude adjustment incorporated.