Loading ...
Sorry, an error occurred while loading the content.

Re: [cc2-dev-l] XP toolkit: questions about arcs

Expand Messages
  • L. Lee Saunders
    Hi Chris, ... When I wrote the ATTC command I had to find out the exact same information. Here is the code from ATTC to find a point on an arc. (or circle or
    Message 1 of 4 , Jul 2, 2000
    • 0 Attachment
      Hi Chris,

      >I'm tackling an XP command involving arcs, and I'm wondering
      >if anyone can answer the following questions:
      >- Is there an easy way to get a point along a specified
      > arc, i.e. is there a function that takes an GARC2
      > structure and a parameter T between 0 and 1, and
      > returns the point corresponding to the given T on the
      > given arc?

      When I wrote the ATTC command I had to find out the exact same information.
      Here is the code from ATTC to find a point on an arc.

      (or circle or line or smooth poly. The onlything that it does not work on
      is the non-smooth poly. If you need to know about the non-smooth poly at a
      later time, I have that code as well)

      GPOINT2 Pt;
      PENTREC pEntRec;

      Pt.x=i*(1/(float)Length)*100;
      EAttach(pEntRec, AT_PCT, &Pt, &Pt);
      ENearT2(pEntRec, Pt.x, Pt.y, ENEARF_ON, &T);


      >- How would one utilize the toolkit to go about deriving
      > an arc that fits three given points? I'm trying to
      > do something similar to what the ARCB command does in
      > CC2, and I'm assuming that there is a toolkit function
      > that fits an arc to three given points, but I can't
      > find it.

      The main properties of an arc are:

      GCIR2 Circle;
      float SAng;
      float AngW;

      and GCIR2's main properties are;

      GPOINT2 Center;
      float Radius;

      So first you find the Point 'A' and Point 'B'
      The midpoint of these two points = Center
      The distance from either 'A' or 'B' to Center = Radius

      So, all you need now is SAng and AngW.

      Go two CC2 and draw an arc.

      Point 'A' = 0,0
      Point 'B' = 100,0
      Point 'C' = 50,50

      Now call up the Info on the arc. It says that the starting angle is 360
      degrees. If you remember your trig, all angles start at 3 o'clock and sweep
      counter clockwise. 3 o'clock can be considered a horizontal line going to
      the right from the center point.

      CC2 seems to want the starting angle to be as near 3 o'clock as possible.
      It starts with point 'A' at the 9 o'clock point and then sweeps
      counter-clockwise to find point 'B'. Point 'B' is at 3 o'clock which is 0
      degrees or 360 degrees since 0 degrees = 360 degrees. You will get the same
      arc with both but CC2 uses 360 degrees.

      If point 'B' is entered first, then point 'A' then the Sang is 0 degrees.
      I'm thinking that this helps CC2 determine direction the arc is drawn, but
      I'm not sure.

      To find SAng use the Angle command:

      #define Angle _Angle
      float _stdcall Angle(float x1,float y1,float x2, float y2);

      So, you could call Angle thus:

      X = Angle(Center.x, Center.y, PointA.x, PointA.y)

      Now all you need is AngW, and that is just the angle of the line from the
      center to point 'A' minus the angle of the line from the center to point 'B'

      180 degrees - 0 degrees = 180 degrees.

      So, the settings to draw a pEntRec of type ARC2 (type #7) are:

      pEntRec->ARC2.Center.x = 50;
      pEntRec->ARC2.Center.y = 0;
      pEntRec->ARC2.Radius = 50;
      pEntRec->ARC2.SAng = 360.0; // Or 0.0
      pEntRec->ARC2.AngW = 108.0;

      Is this just not the funnest thing to do on a Sunday Night? (Actually,
      algorithmns like this are what keep me in the biz!)

      Hope this answers your questions,
      Lee

      ________________________________________________________________________
      Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com
    • Christopher Golden
      (lots of snippage below) ... Thanks, this helps quite a bit! I haven t used EAttach() before, and now I see how useful it can be. ... Hmmm, I think I see a
      Message 2 of 4 , Jul 3, 2000
      • 0 Attachment
        (lots of snippage below)

        L. Lee Saunders wrote:

        > When I wrote the ATTC command I had to find out the exact same information.
        > Here is the code from ATTC to find a point on an arc.

        Thanks, this helps quite a bit! I haven't used EAttach() before,
        and now I see how useful it can be.

        > So first you find the Point 'A' and Point 'B'
        > The midpoint of these two points = Center
        > The distance from either 'A' or 'B' to Center = Radius
        >
        > So, all you need now is SAng and AngW.

        Hmmm, I think I see a problem with this logic. We are starting
        with the (user-chosen) three points -- the starting point of
        the arc (A), the ending point of the arc (B), and another
        arbitrary point along the arc's sweep (C). The problem is that
        the logic above assumes that points A and B are 180 degrees
        apart from each other. But what if the user has chosen A, B,
        and C so that A and B are 45 degrees apart? Then finding the
        halfway point between A and B will yield an incorrect center of
        the arc, because the center in this case is not directly be-
        tween points A and B, but is instead offset to one side or the
        other of a straight line drawn between the points. Thus, I do
        not think that taking the midpoint between A and B will work.

        However, you've gotten me thinking: In essence, what we need
        is a way to find the point that is equidistant from all three
        points provided by the user. We can easily derive an equation
        describing the the infinite line of points that is equidistant
        from A and B. We can do the same for A and C (or B and C,
        doesn't matter). Now we have two line equations, and all we
        need to do is find the point where they intersect. I think
        that this'll provide us with our centerpoint.

        The rest of the algorithm you provided looks just right, thanks
        again Lee!

        Take care,
        Chris G.
        golden@...
      • L. Lee Saunders
        Hi Chris, ... No Problem. I had to go to the source and as FastCAD s creator for the solution when I was first writing ATTC. ... You are correct that my
        Message 3 of 4 , Jul 3, 2000
        • 0 Attachment
          Hi Chris,

          >(lots of snippage below)
          >
          >L. Lee Saunders wrote:
          >
          > > When I wrote the ATTC command I had to find out the exact same
          >information.
          > > Here is the code from ATTC to find a point on an arc.
          >
          >Thanks, this helps quite a bit! I haven't used EAttach() before,
          >and now I see how useful it can be.

          No Problem. I had to go to the source and as FastCAD's creator for the
          solution when I was first writing ATTC.

          > > So first you find the Point 'A' and Point 'B'
          > > The midpoint of these two points = Center
          > > The distance from either 'A' or 'B' to Center = Radius
          > >
          > > So, all you need now is SAng and AngW.
          >
          >Hmmm, I think I see a problem with this logic. We are starting
          >with the (user-chosen) three points -- the starting point of
          >the arc (A), the ending point of the arc (B), and another
          >arbitrary point along the arc's sweep (C). The problem is that
          >the logic above assumes that points A and B are 180 degrees
          >apart from each other. But what if the user has chosen A, B,
          >and C so that A and B are 45 degrees apart? Then finding the
          >halfway point between A and B will yield an incorrect center of
          >the arc, because the center in this case is not directly be-
          >tween points A and B, but is instead offset to one side or the
          >other of a straight line drawn between the points. Thus, I do
          >not think that taking the midpoint between A and B will work.
          >
          >However, you've gotten me thinking: In essence, what we need
          >is a way to find the point that is equidistant from all three
          >points provided by the user. We can easily derive an equation
          >describing the the infinite line of points that is equidistant
          >from A and B. We can do the same for A and C (or B and C,
          >doesn't matter). Now we have two line equations, and all we
          >need to do is find the point where they intersect. I think
          >that this'll provide us with our centerpoint.

          You are correct that my assumtion was wrong. The correct answer to finding
          the center of a circle drawn through three points is to draw two lines
          between either AB, AC, or BC. Then draw two more lines that are at right
          angles (90 degrees) to the first two lines. Where they intersect is the
          center of the circle.

          This is easily done with temporary elements that are not added to the
          database. That way you do not have to do any real hairy calculations. Give
          it a try by doing it by hand. It works!

          >The rest of the algorithm you provided looks just right, thanks
          >again Lee!

          No problem. It just tells me what I already know - late at night
          programming (i.e. problem solving) just does not work well for me! :�

          Lee
          ________________________________________________________________________
          Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com
        • L. Lee Saunders
          Hi Chris, ... finding ... ADD HERE: ... from the center of the line ... ... intersect ... I seem to be batting 1000 for screw-ups this week. :-/ Oh well.
          Message 4 of 4 , Jul 3, 2000
          • 0 Attachment
            Hi Chris,

            > You are correct that my assumtion was wrong. The correct answer to
            finding
            > the center of a circle drawn through three points is to draw two lines
            > between either AB, AC, or BC. Then draw two more lines

            ADD HERE: "... from the center of the line ..."

            > that are at right angles (90 degrees) to the first two lines. Where they
            intersect
            > is the center of the circle.

            I seem to be batting 1000 for screw-ups this week. :-/ Oh well.

            Lee
          Your message has been successfully submitted and would be delivered to recipients shortly.