Jump to content

Recommended Posts

Posted

after searching around I finally found the following code to find the angle between two points:

 

(setq p1 (getpoint "\nSelect First Point: "))
(setq p2 (getpoint "\nSelect Second Point: "))
(setq ang1 (angle p1 p2))

 

However, when I test this by either priting ang1, or by adding the following line of code for text,

(command "_text" "_J" "_tc" "_non" p1 6.0 ang1 "testing angle")

 

the angle seems to only vary from .5 to about 2.0 and never matches what you'd expect from the p1 and p2 angle (perhaps 48 or 89 degrees).

Could it be that the angle it's grabbing is in some other form and I need to convert it?

Posted

Please pay attention that ANGLE function return the angle in radians, while that command is expecting it in degrees.

Posted

Glad to hear that your issue is solved.

Since you will encounter such case many times from now, I strongly suggest you to define a pair of dedicated functions for Radians-to-Degrees, respectively Degrees-to-Radians conversion.

Posted (edited)

Heres the two rtd dtr you want also you need to remember that whilst the answer will always be radians it also ignores the UNITS direction setting so 0 is always horizontal to right so sometimes need a bit extra to take into account the north brg as up page at 0.

 

;The dtr function converts degrees to radians
;The rtd function converts radians to degrees
(defun dtr (a)
(* pi (/ a 180.0))
)
;
(defun rtd (a)
(/ (* a 180.0) pi)
)

Edited by BIGAL
Posted

Building on Mircea and Bigal 's suggestions and answers .

 

(command "_.text" "_J" "_tc" "_non" p1 6.0 (/ (* ang1 180.0) pi) "testing angle")

Posted

Factors you need to consider when using command approach

Current UCS

(setq p1 (getpoint "\nSelect First Point: "))
(setq p2 (getpoint [b][color=blue]p1[/color][/b] "\nSelect Second Point: "))
(setq ang1 (angle [b][color=blue](trans p1 1 0)[/color][/b]
                 [color=blue][b](trans p2 1 0)[/b][/color]))

 

Current textsyle

If Textstyle height is defined on the current TEXTSYLE, instead of "testing angle" you will get the angle value for string and 6.0 as the angle

 

HTH

Posted
If Textstyle height is defined on the current TEXTSYLE, instead of "testing angle" you will get the angle value for string and 6.0 as the angle

That's a good point, pBe; a possible workaround:

(command "_TEXT" textPoint)
(if (= (cdr (assoc 40 (entget (tblobjname "STYLE" (getvar "TEXTSTYLE"))))) 0.0)
(command textHeight)
)
(command textAngle textLabel)

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