Jump to content

Recommended Posts

Posted

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.:?

Posted

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).

Posted (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 by pBe
Posted

@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

:)

Posted

Thanks MSasu, Thanks pBe:) and Thanks Lee Mac

Posted

@Lee Mac: Thanks for pointing me that, have never noticed that feature!

Posted

(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?:x

Posted

Can you post please the error message?

Posted

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")

Posted
@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 :)

Posted

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.

Posted

I am very sorry , It is my mistake. The code is working now correctly.

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...