wimal Posted April 22, 2012 Posted April 22, 2012 Vertical Length =300 Horizon Length = 500 Can anyone write a lisp code to find out the sloping angle in degrees this need to me continue my lisp code. Quote
MSasu Posted April 22, 2012 Posted April 22, 2012 The answer is ATAN function that will give you the angle in radians: (setq theX 500.0 theY 300.0) (setq angleRad (atan (/ theY theX))) ;angle in radians (setq angleDeg (* (/ angleRad pi) 180.0)) ;angle in degrees To write a generic function don't forget to add some conditions (avoid zero division). Quote
pBe Posted April 22, 2012 Posted April 22, 2012 (edited) alternative covnersion: (setq angleDeg [color=blue][b]( cvunit angleRad "radian" "degree")[/b][/color]) (setq p1 (list 0.0 Thex) p2 '(0.0 0.0) p3 (list theY 0.0)) (c:cal "ang(p1,p2,p3)") You may need this for cal to work (if (not (member "geomcal.arx" (arx))) (arxload "geomcal") ) Edited April 22, 2012 by pBe Quote
Lee Mac Posted April 22, 2012 Posted April 22, 2012 @MSasu, This (setq angleRad (atan (/ theY theX))) Could be written: (atan theY theX) The 'atan' function will perform the division and also accounts for the second argument being zero: _$ (atan 1 0) 1.5708 Quote
wimal Posted April 22, 2012 Author Posted April 22, 2012 Thanks MSasu, Thanks pBe:) and Thanks Lee Mac Quote
MSasu Posted April 22, 2012 Posted April 22, 2012 @Lee Mac: Thanks for pointing me that, have never noticed that feature! Quote
wimal Posted April 23, 2012 Author Posted April 23, 2012 (setq theX 500.0 theY 300.0) (setq angleRad (atan (/ theY theX))) ;angle in radians (setq angleDeg (* (/ angleRad pi) 180.0)) ;angle in degrees [color="#4169e1"](command "insert" "RIDGE" P1 "1" "1" angleDeg)[/color] I am trying to insert a block named RIDGE rotating to the calculated angle "angleDeg" But failed. What is the error? Quote
MSasu Posted April 23, 2012 Posted April 23, 2012 At a glance, there are two possible errors: (1) If you are using a localized version of AutoCAD ensure that call the English name of command: (command "_INSERT" "RIDGE" P1 1.0 1.0 angleDeg) (2) Validate that the said block is available in your drawing: (tblsearch "BLOCK" "RIDGE") Quote
Tharwat Posted April 23, 2012 Posted April 23, 2012 @MSasu, (atan theY theX) The 'atan' function will perform the division and also accounts for the second argument being zero: (setq angleRad (atan (/ theY theX))) ;angle in radians Correct it as Lee commented it before Quote
MSasu Posted April 23, 2012 Posted April 23, 2012 Tharwat, I'm not sure that this is the issue, the result is the same: (atan 300.0 500.0) [i]0.54042 [/i](atan (/ 300.0 500.0)) [i]0.54042 [/i](atan 0.6) [i]0.54042[/i] The advantage of Lee Mac's observation is that the statement is simpler and had built-in 0 division protection. Quote
wimal Posted April 23, 2012 Author Posted April 23, 2012 I am very sorry , It is my mistake. The code is working now correctly. Quote
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.