Need Start/End angles (orientation in space) from 3 coordinates

Discussion in 'AutoCAD' started by Darren J. Young, Apr 27, 2004.

  1. What you are looking at here is bulge factor.
    Thanx Bill. I must admit I've always avoided this bulge stuff like the
    plague so I don't quite get what you said but you said enough to make be
    want to work it through and understand it when I get a little breathing
    room.

    --
    Darren J. Young
    CAD/CAM Systems Developer

    Cold Spring Granite Company
    202 South Third Avenue
    Cold Spring, Minnesota 56320

    Email:
    Phone: (320) 685-5045
    Fax: (320) 685-5052
     
    Darren J. Young, Apr 28, 2004
    #21
  2. Darren J. Young

    Jeff Mishler Guest

    Even Jeff's solution doesn't return the correct answer unless you pick
    BZZT! Wrong answer.... ;-)

    My code doesn't provide for picking of the points. It only processes points
    sent to it. Granted they must be sent in the correct order, but it's up to
    the programmer using these functions to pass them correctly.

    (defun C:drawarc ( / p1 p2 p3 startang endang R RP)
    (setq p1 (getpoint "\nSelect arc start point: ")
    p3 (getpoint "\nSelect arc end point: ")
    p2 (getpoint "\nSelect point on arc: ")
    )
    (get_angles p1 p2 p3)
    (setq arc (vlax blah-blah........)
    )

    Jeff
     
    Jeff Mishler, Apr 28, 2004
    #22
  3. Darren J. Young

    BillZ Guest

    I'll work on it some as I get time.

    Once you have the radius and find the center point of the arc, then you take the angle from center to p2 (middle of arc?)
    and add/subtract twice the angle between the chord and the line form the end of the arc to the middle of the arc to get the start/end angles.

    Bill
     
    BillZ, Apr 28, 2004
    #23
  4. Darren J. Young

    BillZ Guest

    Fast & Dirty:

    This really amounts to a quadratic formula but I just used a deflection angle snip (which really seems to do it).

    Bill
     
    BillZ, Apr 28, 2004
    #24
  5. This really amounts to a quadratic formula but I just used a deflection angle snip (which really seems to do it).

    Thanks Bill. I'll examine more closely when I get a chance.


    --
    Darren J. Young
    CAD/CAM Systems Developer

    Cold Spring Granite Company
    202 South Third Avenue
    Cold Spring, Minnesota 56320

    Email:
    Phone: (320) 685-5045
    Fax: (320) 685-5052
     
    Darren J. Young, Apr 28, 2004
    #25
  6. Even Jeff's solution doesn't return the correct answer unless you pick
    But what if I didn't want to worry about that? Just pass 3 random
    points? ;-)

    Agree. I don't need the 3 random points myself but would be interested
    in seeing the math involved if anyone wanted to kill some time. I would
    but I just don't have the brain capacity to do it.

    --
    Darren J. Young
    CAD/CAM Systems Developer

    Cold Spring Granite Company
    202 South Third Avenue
    Cold Spring, Minnesota 56320

    Email:
    Phone: (320) 685-5045
    Fax: (320) 685-5052
     
    Darren J. Young, Apr 28, 2004
    #26
  7. Darren J. Young

    Leo Estember Guest

    If you wanted a purely mathematical solution, you
    have first to determine the center point of arc
    using the distance formula and then get the slope
    of each line connecting the center point to the end
    points of the arc. To get the angle, use the arc tangent
    of the slope.

    Here's how you'll do this: (pseudocode).
    1). Using the distance formula, determine the midpoint
    of the arc from the points given. Get distances from
    P1 to P2 and P1 to P3. If the distances are equal, then
    P1 is the midpoint. If unequal, the larger distance is the
    chord and the 2 points are the endpoints of the arc.
    2) Determine the midpoint coordinates of the chord and the
    sagitta using the distance formula. Then calculate the
    radius of the arc.
    3) Determine the coordinates of the arc's center point using
    the distance formula and the calculated radius. There are
    3 known points and one unknown point (X,Y). You can get
    3 equations in 2 unknown (x^2 and y^2).
    4) With x and y known (center point coordinates) and using
    the slope formula, calculate the slope of the 2 lines
    connecting the center point and the arc's endpoints.
    5) Using the arc tangent formula, get the angles of the 2
    lines.

    Here's the formulas:

    Distance formula:

    Distance^2=(Xend-Xstart)^2 + (Yend-Ystart)^2

    Slope Formula:

    Slope=(Yend-Ystart)/(Xend-Xstart)

    Arc Tangent Formula:

    Angle=ArcTangent (Slope)

    These formulas/procedure can be used on any
    programming language you want or you can
    improvise when needed.

    Hth.

    Leo
     
    Leo Estember, Apr 28, 2004
    #27
  8. Without knowing which one is the start and which one is the end, there are
    True. I guess thinking however that you'd still know the middle. That
    is, if you know the "termination" points and someplace in the middle,
    there's only one arc that will fit.

    The reason this would be helpful is that passing start/end angles to
    (entget) or a VLA function, requires that you pass the proper start
    angle and proper end angle (in a predictable order) to get the proper
    arc. If I'm following along a polyline path, I don't always know if
    that path is oriented CW or CCW which means I'd know the "termination
    points" of an arc and a point in the middle someplace, but I don't know
    if a particular termination should be a "start" or "end".

    --
    Darren J. Young
    CAD/CAM Systems Developer

    Cold Spring Granite Company
    202 South Third Avenue
    Cold Spring, Minnesota 56320

    Email:
    Phone: (320) 685-5045
    Fax: (320) 685-5052
     
    Darren J. Young, Apr 28, 2004
    #28
  9. Darren J. Young

    Jeff Mishler Guest

    If I'm following along a polyline path, I don't always know if
    If that's the case, here's a little routine that will create an arc based on
    input points, if the point selected as a point on the arc doesn't fall on
    the arc created (the opposite one was created) then it is deleted and the
    proper one is created.

    (defun c:drawarc (/ arc1)
    (setq p1 (getpoint "\nSelect first arc point: ")
    p2 (getpoint "\nSelect point on arc: ")
    p3 (getpoint "\nSelect third arc point: ")
    )
    (get_angles p1 p2 p3)
    (setq arc1 (vlax-invoke (get_space) "addarc" RP R startang endang))
    (vla-put-color arc1 acblue)
    (if (not (vlax-curve-getdistatpoint arc1 p2))
    (progn
    (vla-delete arc1)
    (get_angles p3 p2 p1)
    (setq arc1 (vlax-invoke (get_space) "addarc" RP R startang endang))
    (vla-put-color arc1 acblue)
    )
    )
    )

    Like I said, it's up to the programmer to make sure the 'correct' data is
    passed to the functions.

    HTH,
    Jeff
     
    Jeff Mishler, Apr 28, 2004
    #29
  10. Like I said, it's up to the programmer to make sure the 'correct' data is
    True, but the point of utility functions is to make programming easier
    for the programmer. If by adding in the intelligence up front in a
    library function saves time be eliminating adding that same intelligence
    50 times for 50 different programs, then IMO it should go into the
    utility function more times than not.

    In my case, I've always hated working with angles because at some point,
    they reset to zero. Are I coming, going, getting bigger, smaller, is it
    the big angle or the small angle, clockwise, counter clockwise, etc.?
    I'd rather build all I can into those types of functions so I never have
    to worry about doing it again.

    --
    Darren J. Young
    CAD/CAM Systems Developer

    Cold Spring Granite Company
    202 South Third Avenue
    Cold Spring, Minnesota 56320

    Email:
    Phone: (320) 685-5045
    Fax: (320) 685-5052
     
    Darren J. Young, Apr 28, 2004
    #30
  11. Darren J. Young

    devitg Guest

    Meanwhile I write the proper explanation to the following , I put it
    Given the chord , and the sagitta
    I will call
    chord = 2 C
    sagitta = S
    I can tell you that the circle diameter where the arc belong

    D = (C^2/S ) + S
    It is the same as D/2 = (c^2+a^2 )/2s = R
    But the previous ,long formula, comes from the Pitagorean Theorem where c^2= a^2 + B^2.

    The second come from triangle similitude.


    Now I will try put in clear all this stuff, when ready I will post it here.
     
    devitg, Apr 28, 2004
    #31
  12. Darren J. Young

    Jeff Mishler Guest

    Ok, here ya go, along with a sample routine that utilizes the data. No error
    checking/handling provided. The only assumption the function makes is that
    the second point entered lies on the arc.

    Enjoy! I know I did figuring this all out. Now if I could just nail down
    that last little part.......

    Jeff


    ;| Routine and associated functions to draw an arc given the two endpoints
    and a point on the arc. One of the functions still needs some work....
    Jeff Mishler April 28, 2004
    |;
    (defun c:drawarc (/ arc1 p1 p2 p3 ang_list)
    (and (setq p1 (getpoint "\nSelect first arc point: ")
    p2 (getpoint "\nSelect point on arc: ")
    p3 (getpoint "\nSelect third arc point: ")
    *doc* (vla-get-activedocument (vlax-get-acad-object))
    )
    (not (vla-startundomark *doc*))
    (setq ang_list (get_angles p1 p2 p3))
    (setq arc1 (vlax-invoke (get_space) "addarc"
    (car ang_list) (cadr ang_list)
    (caddr ang_list) (cadddr ang_list)))
    (vla-put-color arc1 acblue)
    (not (vla-endundomark *doc*))
    )
    (princ)
    )

    (defun rad3pts (p1 p2 p3 / A B C R q)
    (setq A (distance p1 p2)
    B (distance p2 p3)
    C (distance p1 p3)
    )
    (setq q (/ (- (+ (expt A 2)(expt B 2)) (expt C 2)) (* 2 A B)))
    (/ C (* 2 (sqrt (- 1 (expt q 2)))))
    )

    (defun radPnt (p1 p2 p3 R / halfchord l1 halfpt RP)
    (setq halfchord (/ (distance p1 p3) 2)
    l1 (sqrt (- (expt R 2) (expt halfchord 2)))
    halfpt (polar p1 (angle p1 p3) halfchord)
    )
    (setq RP (polar halfpt (- (angle p1 p3) (/ pi 2)) l1))
    (if (not (equal R (distance p2 RP) 0.0000001))
    (setq RP (polar halfpt (+ (angle p1 p3) (/ pi 2)) l1))
    )
    RP
    )

    (defun get_angles (p1 p2 p3 / R RP startang endang arc1)
    (setq R (rad3pts p1 p2 p3)
    RP (radPnt p1 p2 p3 R))
    ;;***** The following needs to be revised to avoid adding & deleting
    ;; an entity but I have gone brain dead and can't seem to find the
    ;; correct mathematical equation......
    (setq startang (angle RP p1)
    endang (angle RP p3)
    )
    (setq arc1 (vlax-invoke (get_space) "addarc" RP R startang endang))
    (if (not (vlax-curve-getdistatpoint arc1 p2))
    (setq startang (angle RP p3)
    endang (angle RP p1)
    )
    )
    (vla-delete arc1)
    ;;;********* End needed revision
    (list RP R startang endang)
    )


    ;;derived from input by Luis Esquivel & Doug Broad
    (defun get_space ()
    (if (= 1 (vla-get-activespace *doc*))
    (vla-get-modelspace *doc*);we're in modelspace
    (if (= (vla-get-mspace *doc*) :vlax-true)
    (vla-get-modelspace *doc*);we're in modelspace
    ;thru paperspace VPort
    (vla-get-paperspace *doc*);we're in paperspace
    )
    )
    )
     
    Jeff Mishler, Apr 29, 2004
    #32
  13. Darren J. Young

    Jeff Mishler Guest

    Not exactly.... with the exception of about 2 years, I've been in the Civil
    Eng./Land Surveying business since 1978 though.
    Do I, <egads do I want to know the answer to this>, sound like one?

    Jeff
     
    Jeff Mishler, Apr 29, 2004
    #33
  14. Darren J. Young

    Jeff Mishler Guest

    "> it was base on your answers.... maybe whenever i need to verify some
    civil
    I'd be happy to. You can email direct, if desired, to

    Jeff
     
    Jeff Mishler, Apr 29, 2004
    #34
  15. Darren J. Young

    BillZ Guest

    Here another version.
    You just pick the arc.
    Points are always "right" that way.
    Be careful the names are the same.


    Bill
     
    BillZ, Apr 29, 2004
    #35
  16. Here another version.
    Hi Bill!

    I don't think I'm understanding the point of this one. If the goal is to
    get the start/end angle of an arc, it's slightly over engineered because
    you are prompting for the selection of the arc and the arc's internal
    data will always list the start/end angles correctly/CCW (they won't be
    reversed). You just need to extract them. Or am I missing something?

    Of course, my comments make no consideration of ANGBASE settings.

    --
    Darren J. Young
    CAD/CAM Systems Developer

    Cold Spring Granite Company
    202 South Third Avenue
    Cold Spring, Minnesota 56320

    Email:
    Phone: (320) 685-5045
    Fax: (320) 685-5052
     
    Darren J. Young, Apr 29, 2004
    #36
  17. Darren J. Young

    Jeff Mishler Guest

    Darren, did you see my final version yesterday? Luis replied shortly after I
    posted and you may have missed it.

    It allows the entering of an end point, point on arc, other endpoint and
    will always draw the arc correctly.

    Jeff
     
    Jeff Mishler, Apr 29, 2004
    #37
  18. Darren J. Young

    BillZ Guest

    Hi Bill!
    Darren,
    I wasn't sure what/why you wanted the start/end angles in the first place just because I knew they were already in the entity data and you already turned down one offer to get them that way.
    That aside, this new version will get start point and end point of the arc and find the middle of the arc exactly, which is necessary when determining the parameters of an arc with angles.
    The problem with a 3 point arc is that the second point doesn't have to be "in the middle" for AutoCAD to draw it, so doing it that way tells you nothing about the arc.
    If you are trying to create an arc mathematically, and if you have only the endpoints and the chord, you still must have either the length of the arc, included angle, the bulge, or the radius to arrive at the other defining features of the arc.

    Bill
     
    BillZ, Apr 29, 2004
    #38
  19. Darren J. Young

    devitg Guest

    If you are trying to create an arc mathematically, and if you have only the endpoints and the chord, you still must have either the length of the arc, included angle, the bulge, or the radius to arrive at the other defining features of the arc.

    If you have the chord and sagitta it is enougth to get all other values of the arc.
    Please see my previous post
     
    devitg, Apr 29, 2004
    #39
  20. I wasn't sure what/why you wanted the start/end angles in the first place just because I knew they were already in the entity data and you already turned down one offer to get them that way.
    Here's what's going on. I though I'd explained the previously but
    perhaps not. At least not well enough that others understood it.

    I'm creating a routine that will redraw a path of lines & arcs based on
    a polyline, splined polyline, spline, etc.

    Any existing polyline "thining" routines I've seen seem to simply remove
    points based on the amount of change in angle from one segment to the
    other....oh...and most don't work on splines.

    Making extensive use of the vlax-curve-* functions, I'm walking around
    an given polyline/spline,etc. From a given point, I look ahead a user
    configurable distance. From where I'm at, I've got PT1. From the
    distance I'm looking ahead, I've got PT3. 1/2 that distance I've got
    PT2. I've got 3 points that "define" an arc (assuming they aren't all
    co-linear which I'm also checking for) which to this point is NOT drawn.
    Now I could draw a 3 pt arc with AutoCAD using a call to (command) but
    I'd prefer to use ENTMOD or VLA methods because it's been my experiance
    that (command) is slower, especially considering that this will need to
    be done several hundereds of thousands of times (perhaps over a million)
    in some files depending on the parameters I specify for how much I want
    to allow the new path to deviate from the original polyline/spline.

    Because I've got 3 points, I need to determine which direction the arc
    is so it can be drawn correctly with a proper start/end angle so I don't
    end up opposite of what I want. Once the arc is drawn, I check a
    configurable number of locations along that arc for their distance to
    the original polyline/spline. If they are all within the specificed
    deviation tolerance, I erase the arc, move fuurther and do it again
    until I've exceded the allowable deviation from the original path, then
    I go back one step and create the segment. Once that segment is created,
    I start the process all over again for the next segement.

    A long process, but I'm not concerned with speed nearly as much as I am
    accuracy although I'm not going to draw any more acrs than needed
    because it would slow down a slow process even more.

    Because as I'm working down a polyline/spline, I end up with 3 points, I
    won't nessicarily know which order the start/end needs to be in to draw
    the proper arc using proper stare/end angles. Mathamatically it can be
    figured out, and I'm doing that now, but it's not being done in the same
    formula/code as what's returning the start/end angles, I'm doing it
    elsewhere.

    I've got all the code I need. I'm not asking for any more out of need.
    Rather, I shifted into discussion mode about "What would be nice" and
    perhaps didn't clearly communicate that.


    --
    Darren J. Young
    CAD/CAM Systems Developer

    Cold Spring Granite Company
    202 South Third Avenue
    Cold Spring, Minnesota 56320

    Email:
    Phone: (320) 685-5045
    Fax: (320) 685-5052
     
    Darren J. Young, Apr 29, 2004
    #40
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.