Sin(x) curve

Discussion in 'AutoCAD' started by SuperMick, May 17, 2004.

  1. SuperMick

    SuperMick Guest

    How can I plot a Sin(x) curve in AutoCAD with AutoLISP ?
     
    SuperMick, May 17, 2004
    #1
  2. SuperMick

    David Bethel Guest

    (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
     
    David Bethel, May 17, 2004
    #2
  3. SuperMick

    David Bethel Guest

    On second thought:

    (repeat (1+ rep)

    Will give you a complete wave. -David
     
    David Bethel, May 17, 2004
    #3
  4. Cheers :) - That will come in handy

    / STUPID QUESTION ALERT /
    Why is the lisp function for tan called atan?
     
    Thomas 'bacco|007' Baxter, May 18, 2004
    #4
  5. SuperMick

    randy benson Guest

    atan is arctan --> returns angle in radians

     
    randy benson, May 18, 2004
    #5
  6. SuperMick

    BillZ Guest

    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
     
    BillZ, May 18, 2004
    #6
  7. SuperMick

    devitg Guest

    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
     
    devitg, May 18, 2004
    #7
  8. SuperMick

    David Bethel Guest

    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)
     
    David Bethel, May 19, 2004
    #8
  9. SuperMick

    btlsp Guest

    btlsp, May 21, 2004
    #9
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.