arc in VBA - any wizzkids out there ?

Discussion in 'AutoCAD' started by VBA-Jan, Sep 20, 2004.

  1. VBA-Jan

    VBA-Jan Guest

    I'm trying to draw an arc using VBA. However, I DON'T know the arc's center point, nor the radius. I DO know the start angle, end angle and one point on the arc.

    Does anyone know how to do this in VBA ??

    Thanks a lot !!

    Jan
     
    VBA-Jan, Sep 20, 2004
    #1
  2. Hi Jan,

    You have insufficient information to define a unique arc. There are an
    infinite number of arcs which pass through a point with the same start an
    end angle.

    --


    Laurie Comerford
    CADApps
    www.cadapps.com.au

    center point, nor the radius. I DO know the start angle, end angle and one
    point on the arc.
     
    Laurie Comerford, Sep 20, 2004
    #2
  3. VBA-Jan

    VBA-Jan Guest

    Thanks for your reply, Laurie.
    I didn't mention that I am trying to make a sort of fillet tool.
    So I have two lines or plines or whatever, and a point.
    Now I want to create an arc, that has the same angle as
    the line at the start and endpoint.

    Do you have any clue how to perform that trick ?
     
    VBA-Jan, Sep 21, 2004
    #3
  4. Hi,

    This may not be acceptable, but simply buy Land Desktop. It has this
    command built in.

    I don't know a specific algorithm for this, but you could try iterating a
    trial radius and using offsets of the lines, comparing the distance to the
    intersection of the offset lines to the point.

    --

    Regards


    Laurie Comerford
    www.cadapps.com.au
     
    Laurie Comerford, Sep 21, 2004
    #4
  5. VBA-Jan

    Thomas Homan Guest

    Jan,

    I hope you've got your Geometry/trig hat firmly affixed. I haven't worked
    out the coding, but it should be simple enough.

    The basics:

    If you have an arc with 3 points on it, (2 ends and 1 point on the arc) the
    center point and radius are fairly easy to find. It works out that if you
    have 3 points on an arc, the lines perpendicular to the chords intersect at
    the center point

    Center point:

    Given/assumptions: 3 points - I'll assume that by having the start angle,
    you also have the start POINT. The same goes for the end POINT

    Ax,y - Start angle point (4,4)

    Bx,y - End angle point (1,1)

    Cx,y - point on arc (1.5,3)

    Px,y - Center point of arc

    Find the midpoints and angles of the AC and BC chords

    Mac = (4+1.5)/2,(4+3)/2 = 2.75,3.5

    Mbc = (1+1.5)/2,(1+3)/2 = 1.25,2

    Aac = atan((ay-cy)/(ax-cx)) = atan(1/2.5) = 0.380506 (radians) = 21.8014
    (deg) Abc = atan((by-cy)/(bx-cx)) = atan(2/0.5) = 1.325828 (rad) = 75.96376
    (deg) These angles are NOT absolute. Pay attention to your circle PERFORM
    ANGLE REALITY CHECKS!!!!

    The math will easily send you in the WRONG DIRECTION!!! And you may not know
    until the end of the calcs.

    Get the chord length between Mac and Mbc

    Lacbc = sqrt(x^2+y^2) = sqrt((2.75-1.25)^2+(3.5-2)^2) = 2.1213

    Determine Angle between Mbc and C

    This is the angle with point C in the middle and segments CB and CA Abca =
    125.838 deg. = 2.196287 (rad)- Note how the 21.8... + 75.9... Values don't
    add up to the actual angle if laid out in acad. It has to do with the
    movement through the 360deg section of the circle. The 75 deg value becomes
    255.964 if reversed. Which equates to a closing angle of 104.036 + the
    21.8014 to give the actual angle of 125.838. Rather confusing but mus be
    delt with.

    Now then, back to trig

    Determine inside angles of the triangle defined by Point C, Mbc and Mac Ambc
    = 30.964 deg - Had to use obtuse law of sines here due to large (>90) angle
    at Point C Amac = 23.199 deg - Had to use obtuse law of sines here due to
    large (>90) angle at Point C

    So, the angle between the chord of Mbc and Mac and the line from Mbc to P is

    180 - 90 (perpendicular) - 30.964 (inside) = 59.036 deg

    The angle between the chord of Mbc and Mac and the line from Mac to P is
    180 - 90 - 23.199 = 66.801 deg = 1.165897 rad

    Next,

    Solve for the length of the line from Mbc to P using law of sines Angle P =
    180-59.036-66.801 = 54.163 (deg) = 0.945323 (rad) Leg length =
    (2.1213*sin( 66.801))/sin(54.163) = 2.4051 Note: Actual degree angle is used
    here rather than radian value Leg Mca to P =
    (2.1213*sin(59.036))/sin(54.163) = 2.2438 Note: Actual degree angle is used
    here rather than radian value

    Finally,

    Use the POLARPOINT vba function, feeding in

    Starting point (Mbc) (1.25,2)

    Angle (345.964) 6.038211 radians - derrived from Anglebc (75.964) and then
    rotating right 90 deg - again, VALIDATE direction needed to be turned! Why
    head off in the wrong direction Distance (2.4051)

    This will return a vairant record with your center point.

    I would do the same down the other leg to verify that your points agree
    within some tolerance as a validity check.

    The radius is a simple calc using the pythag therum for a right triangle to
    solve for hyp. From P to A,B or C. Your choice

    Sorry so messy but that's what it takes given your starting conditions.
    Also, error check everywhere! I'm planning on pasting a function up due to
    amount of error checking coding alone.

    My email is correct if you want to further this conversation offline. I'll
    save the labeled acad drawing for your reference and send it offline. It
    should clear up a few questions.

    Regards,

    Thomas Homan

    center point, nor the radius. I DO know the start angle, end angle and one
    point on the arc.
     
    Thomas Homan, Sep 23, 2004
    #5
  6. Thomas, I'd love to see the ACAD file myself. Can you send it offline to
    me? Jan's problem stuck with me, and I couldn't help plugging away on it
    too.

    Thanks,
    James
     
    James Belshan, Sep 23, 2004
    #6
  7. VBA-Jan

    VBA-Jan Guest

    Wow, Thomas.
    I really will have to take a closer look at this one.
    I didn't realize there was so much math / trig involved in solving my question. Although my math is quite all right I couldn't figure it out myself right away.

    Thanks for your reply !! I will get into it over the weekend and see how it turns out in code.
     
    VBA-Jan, Sep 24, 2004
    #7
  8. it turns out in code.


    Jan,
    Please let us know how this problem goes for you, and if you still need help
    on it.

    James
     
    James Belshan, Sep 29, 2004
    #8
  9. VBA-Jan

    VBA-Jan Guest

    James,

    I haven't had time to try it out yet.
    I'll post my findings asap.

    Jan
     
    VBA-Jan, Sep 30, 2004
    #9
  10. VBA-Jan

    Thomas Homan Guest

    Are you looking for the code, or the sample drawing representing the math?

    Sorry for the long response, I had to go over to Italy for 3 weeks.

    Regards,

    Tom
     
    Thomas Homan, Oct 22, 2004
    #10
  11. The sketch, so I could re-read your explanation with it. I had tackled the
    problem assuming I didn't know the tangent points of the fillet arc. I got
    as far as solving a 4-th order polynomial (found long formulas for its roots
    on Google), but then had to put it down. I haven't looked at it in a couple
    weeks now. When I find some more free time I'll try to wrap it up and see
    if I get any correct answers.

    I hope your travel was for fun. I'm jealous.

    James
     
    James Belshan, Oct 22, 2004
    #11
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.