Angle between three points

Discussion in 'AutoCAD' started by srinivasan, Dec 11, 2004.

  1. srinivasan

    srinivasan Guest

    Hello all

    Is there any way to calculate the angle between three
    points, ///r to dimangular vertex option.

    Thanks in advance.
    Sri
     
    srinivasan, Dec 11, 2004
    #1
  2. Maybe two calls to the Utility object's AngleFromXAxis method and some
    arithmetic.
     
    John Goodfellow, Dec 11, 2004
    #2
  3. srinivasan

    krispy Guest

    here is a lisp that will return the angle enclosed between three points, where ip is the intersecting point and pt1 and pt2 are the other points:
    Here is the code:
    Code:
    (defun enclAngle(pt1 pt2 ip / dist1 dist2 dist3)
    (setq dist1 (distance pt1 ip)
    dist2 (distance pt2 ip)
    dist3 (distance pt1 pt2)
    );setq
    ;; angle = acos((a^2 + b^2 - c^2) / (2*a*b))
    (acos (/ (- (+ (sqr dist1) (sqr dist2)) (sqr dist3)) (* 2 dist1 dist2)))
    );enclAngle
    
    
    
    ;;; acos returns the inverse of a cosine
    ;;; acos(X) = atan(-X / sqrt(-X*X+1)) + 2*atan(1)
    (defun acos(value)
    (+
    (atan (/	(- 0 value)	(sqrt (+ (* (- 0 value) value) 1))))
    (* 2 (atan 1))
    );+
    );acos
    
    ;;;not sure if sqr is built in
    (defun sqr(num)
    (* num num)
    );sqr
    
     
    krispy, Dec 12, 2004
    #3
  4. srinivasan

    devitg Guest

    There is a easy way , the old reliable CAL command

    (if (= cal nil)
    (arxload "geomcal")
    )
    ;; just to chek if GEOMCAL is loaded

    (Setq encAngle (c:cal "ang(apex,p1,p2)"));_ the angle included in p1 p2 with
    intersection point as apex


    Just a KISS: keep it simple .....Sir

    Gabriel
     
    devitg, Dec 13, 2004
    #4
  5. srinivasan

    krispy Guest

    now where's the fun in that?
    :)
     
    krispy, Dec 13, 2004
    #5
  6. srinivasan

    krispy Guest

    i think it only fair to point out that instead of:
    (c:cal "expression")
    you can use
    (cal "expression")
    hence saving you an additional two key strokes
    lol
     
    krispy, Dec 13, 2004
    #6
  7. srinivasan

    srinivasan Guest

    Thanks all.
     
    srinivasan, Dec 13, 2004
    #7
  8. This should do it (I leave the testing to you):
    The function TPA should return the angle in radians between the three points
    (cp is the common point).


    Private Function TPA(p1 As Variant, p2 As Variant, cp As Variant) As Double
    TPA = Gang(gDX(p1, cp), gDY(p1, cp)) + Gang(gDX(p2, cp), gDY(p2, cp))
    End Function

    Private Function gDX(pa As Variant, pb As Variant) As Double
    gDX = Abs(pb(0) - pa(0))
    End Function

    Private Function gDY(pa As Variant, pb As Variant) As Double
    gDY = Abs(pb(1) - pa(1))
    End Function

    Private Function Gang(DX As Double, DY As Double) As Double
    If DY = 0 Then Gang = 0 Else Gang = Atn(DY / DX)
    End Function
     
    Jorge Jimenez, Dec 13, 2004
    #8
  9. Sorry, last function should be:

    Private Function Gang(DX As Double, DY As Double) As Double
    If DX = 0 Then Gang = 0 Else Gang = Atn(DY / DX)
    End Function
     
    Jorge Jimenez, Dec 13, 2004
    #9
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.