Jump to content

Need Help Creating a Lisp Routine


Subidoooo

Recommended Posts

Hi guys can someone please help me with this lisp routing? I have to calculate the following every day and having a lisp routing will make it so much more easier.

 

1/tan(73) = 0.30573

 

the 73 needs to be an input value from the user

 

 

Link to comment
Share on other sites

Is that the right formula?

1/Tan(73) = 1.0878

 

(defun c:foo (/ x a)
  (setq x (getreal "\n Input Angle: "))
  (setq a (/ 1 (tan x)))
  (prompt (strcat "1/tan(" (rtos x 2 2) ")=" (rtos a 2 6)))
  (princ)
)  
;; http://lee-mac.com/mathematicalfunctions.html#trigonometric
;; Tangent  -  Lee Mac
;; Args: x - real
(defun tan ( x )
    (if (not (equal 0.0 (cos x) 1e-10))
        (/ (sin x) (cos x))
    )
)

 

  • Like 1
Link to comment
Share on other sites

Ahh, beat me mhupp, anyway here is mine

(defun c:tnx (/ a b)
   (setq a (getreal "\nPlease enter the value of the angle: ")
         b (if (not (equal (cos (/ (* pi a) 180.0)) 0. 1e-10))
              (/ 1 (/ (sin (/ (* pi a) 180.0)) (cos (/ (* pi a) 180.0))))
              "Undefined"
           )
   )
   (if (= b "Undefined")
      (prompt "\nThe value is Undefined ")
      (prompt (strcat "\nThe value is: " (rtos b 2 6) " "))
   )
   (princ)
)

This is considering you are using decimal degrees, added a restriction if Cos function equals 0.0

Edited by Isaac26a
  • Like 1
Link to comment
Share on other sites

10 hours ago, mhupp said:

Is that the right formula?

1/Tan(73) = 1.0878

 

(defun c:foo (/ x a)
  (setq x (getreal "\n Input Angle: "))
  (setq a (/ 1 (tan x)))
  (prompt (strcat "1/tan(" (rtos x 2 2) ")=" (rtos a 2 6)))
  (princ)
)  
;; http://lee-mac.com/mathematicalfunctions.html#trigonometric
;; Tangent  -  Lee Mac
;; Args: x - real
(defun tan ( x )
    (if (not (equal 0.0 (cos x) 1e-10))
        (/ (sin x) (cos x))
    )
)

 

If you use a sienctific calculator. You will get the same results as me. I will give the kisp a shot

Link to comment
Share on other sites

9 hours ago, Isaac26a said:

Ahh, beat me mhupp, anyway here is mine

(defun c:tnx (/ a b)
   (setq a (getreal "\nPlease enter the value of the angle: ")
         b (if (not (equal (cos (/ (* pi a) 180.0)) 0. 1e-10))
              (/ 1 (/ (sin (/ (* pi a) 180.0)) (cos (/ (* pi a) 180.0))))
              "Undefined"
           )
   )
   (if (= b "Undefined")
      (prompt "\nThe value is Undefined ")
      (prompt (strcat "\nThe value is: " (rtos b 2 6) " "))
   )
   (princ)
)

This is considering you are using decimal degrees, added a restriction if Cos function equals 0.0

Tried your version and it works, thank you. this forum is very active

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...