Subidoooo Posted December 26, 2022 Share Posted December 26, 2022 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 Quote Link to comment Share on other sites More sharing options...
mhupp Posted December 26, 2022 Share Posted December 26, 2022 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)) ) ) 1 Quote Link to comment Share on other sites More sharing options...
Isaac26a Posted December 26, 2022 Share Posted December 26, 2022 (edited) 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 December 26, 2022 by Isaac26a 1 Quote Link to comment Share on other sites More sharing options...
Subidoooo Posted December 27, 2022 Author Share Posted December 27, 2022 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 Quote Link to comment Share on other sites More sharing options...
Subidoooo Posted December 27, 2022 Author Share Posted December 27, 2022 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 Quote Link to comment Share on other sites More sharing options...
mhupp Posted December 27, 2022 Share Posted December 27, 2022 oops was in Radians Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.