+ Reply to Thread
Results 1 to 8 of 8
  1. #1
    Forum Newbie
    Using
    AutoCAD 2011
    Join Date
    Jun 2012
    Posts
    8

    Default get angle between two points

    Registered forum members do not see this ad.

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

    Code:
    (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,
    Code:
    (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?

  2. #2
    Forum Deity MSasu's Avatar
    Discipline
    Construction
    MSasu's Discipline Details
    Occupation
    engineer
    Discipline
    Construction
    Details
    AutoLISP programmer
    Using
    AutoCAD 2013
    Join Date
    Mar 2009
    Location
    Brasov, Romania
    Posts
    3,000

    Default

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

    AutoCAD's happy user equation: FILEDIA + PICKADD² + PICKFIRST = 3

  3. #3
    Forum Newbie
    Using
    AutoCAD 2011
    Join Date
    Jun 2012
    Posts
    8

    Default

    That was it, thanks!!!

  4. #4
    Forum Deity MSasu's Avatar
    Discipline
    Construction
    MSasu's Discipline Details
    Occupation
    engineer
    Discipline
    Construction
    Details
    AutoLISP programmer
    Using
    AutoCAD 2013
    Join Date
    Mar 2009
    Location
    Brasov, Romania
    Posts
    3,000

    Default

    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.
    Regards,
    Mircea

    AutoCAD's happy user equation: FILEDIA + PICKADD² + PICKFIRST = 3

  5. #5
    Forum Deity
    Using
    Civil 3D 2013
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    3,785

    Default

    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.

    Code:
    ;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)
    )
    Last edited by BIGAL; 10th Jul 2012 at 06:33 am.
    A man who never made mistakes never made anything

  6. #6
    Forum Deity Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draftsman
    Discipline
    Mechanical
    Using
    AutoCAD 2014
    Join Date
    Oct 2009
    Location
    Lives in Abu Dhabi
    Posts
    2,627

    Default

    Building on Mircea and Bigal 's suggestions and answers .

    Code:
    (command "_.text" "_J" "_tc" "_non" p1 6.0 (/ (* ang1 180.0) pi) "testing angle")
    - When aim is being settled in my mind , I have to reach it and get it in hand whatever it costs and wherever it is and will never give up . Tharwat said

  7. #7
    Forum Deity pBe's Avatar
    Computer Details
    pBe's Computer Details
    Operating System:
    Windows XP
    Discipline
    Construction
    pBe's Discipline Details
    Discipline
    Construction
    Details
    Camp Construction planning and details
    Using
    AutoCAD 2009
    Join Date
    Apr 2010
    Posts
    2,097

    Default

    Factors you need to consider when using command approach
    Current UCS
    Code:
    (setq p1 (getpoint "\nSelect First Point: "))
    (setq p2 (getpoint p1 "\nSelect Second Point: "))
    (setq ang1 (angle (trans p1 1 0)
                      (trans p2 1 0)))
    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

  8. #8
    Forum Deity MSasu's Avatar
    Discipline
    Construction
    MSasu's Discipline Details
    Occupation
    engineer
    Discipline
    Construction
    Details
    AutoLISP programmer
    Using
    AutoCAD 2013
    Join Date
    Mar 2009
    Location
    Brasov, Romania
    Posts
    3,000

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by pBe View Post
    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:
    Code:
    (command "_TEXT" textPoint)
    (if (= (cdr (assoc 40 (entget (tblobjname "STYLE" (getvar "TEXTSTYLE"))))) 0.0)
     (command textHeight)
    )
    (command textAngle textLabel)
    Regards,
    Mircea

    AutoCAD's happy user equation: FILEDIA + PICKADD² + PICKFIRST = 3

Similar Threads

  1. Quick way to measure a right angle described by two points?
    By bheilig in forum AutoCAD 2D Drafting, Object Properties & Interface
    Replies: 3
    Last Post: 22nd May 2012, 01:55 am
  2. Rotate an object to match an angle without knowing the angle?
    By BigDog in forum AutoCAD 2D Drafting, Object Properties & Interface
    Replies: 4
    Last Post: 6th Oct 2011, 08:34 am
  3. Angle without knowing two points
    By GMPAO in forum AutoCAD Beginners' Area
    Replies: 31
    Last Post: 29th Oct 2009, 01:01 pm
  4. VBA - Getting angle from 2 points
    By jakebullet70 in forum AutoLISP, Visual LISP & DCL
    Replies: 11
    Last Post: 27th Mar 2009, 04:22 am
  5. How to find the angle between two points please?
    By facad in forum AutoCAD Beginners' Area
    Replies: 7
    Last Post: 7th Oct 2008, 01:16 am

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts