Menu

Help

Dany
2010-02-18
2013-04-30
  • Dany

    Dany - 2010-02-18

    Hello, I wonder how I could draw a line demarcating the end of an arc.
    I drew an arc and I would draw two lines that delimit.
    Put a few lines of code:

    drawXZCircleOrDisk (Radius2, position (), color, 100, false);
    line1 = position () + (forward () * Radius2);
    annotationLine (position (), line1, gGreen);
    drawXZArc (line1, position (), 3.10, gBlack);

    I drew a circle, then a line and then an arc.
    The starting point of the arc is the line that I drew, but how can I draw a second line passing through the last point of the arc?

     
  • Craig Reynolds

    Craig Reynolds - 2010-02-18

    Sorry, I think I let a previous questions drop.  I will assume that is solved or this is a restatement of the previous question.

    First of all, it would make more sense to use all draw… calls or all annotation… calls.  Otherwise there may be a "1 frame's worth of motion" offset between the two.  This would be a superficial problem, not a serious bug.  I think annotation can always be called but draw can only be called in the draw phase of OpenSteerDemo.  Second, drawXZCircleOrDisk is meant to be an internal routine for the "Draw library".  Again not a serious problem to call it directly, but if the last argument is always false, you could call drawXZCircle instead.

    Now (finally!) on to your question.  The point at the end of that arc would be the result of rotating the arc start point by the arc angle, 3.1 in your example.  I have not tested this code but I think that would be:

    position () + (forward () * Radius2).rotateAboutGlobalY (3.1)

    Another way to do with would be to copy the source code of drawXZArc - which already computes this point - and make your own "draw sector outline" routine by adding two drawLine calls to the code from drawXZArc.  (I use "sector" in the sense of http://en.wikipedia.org/wiki/Circular_sector )

     
  • Dany

    Dany - 2010-02-19

    Hello, I wanted to thank you for the help you gave me.
    I managed to draw the arc and the two lines that delimit it.
    Instead of putting 3.1 in rotateAboutGlobalY I put (-4.94) because only with this value the line coincided with the end of the arc.

    radius2 = 2.0;

    line1 = position () + (forward () * radius2);
    line2 = position () + (forward () * radius2). rotateAboutGlobalY (-4.94);

    drawXZCircle (radius2, position (), color, 100);

    drawLine (position (), line1, gWhite);
    drawLine (position (), line2, gWhite);
    drawXZArc (line1, position (), 3.10, gWhite);

    I also followed your other advice.
    I wanted to ask one last thing:
         I could give a name to the arc?
         How could I define the area between the two lines?
    I hope you understand

     
  • Dany

    Dany - 2010-02-20

    HI Craig, I just wanted to ask you something.
    I calculated the area of my field circular.

    How do I draw two lines that delimit the circular sector? NOT BE MY LAST POST.

    float area1 = ((65.9 * 3.142 * ((radius1) ^ 2)) / (360));

     
  • Craig Reynolds

    Craig Reynolds - 2010-02-21

    Once again I am confused, you asked: "How do I draw two lines that delimit the circular sector? NOT BE MY LAST POST."  Isn't this what the two drawLine calls in your previous post do?

    I am also surprised that you found you needed to use -4.94 instead of 3.10 for a rotation angle.  Perhaps there is an order of operations problem? does this version with an extra set of parenthesis work for you?

    line2 = position () + ((forward () * radius2).rotateAboutGlobalY (3.10));

    When you asked "I could give a name to the arc?" did you mean you wanted to display text near the arc?  There is an example of that in OneTurning.cpp, see the call to draw2dTextAt3dLocation.

     
  • Dany

    Dany - 2010-02-21

    Hi Craig
    I have not drawn the lines and the arc because I was interested in the circular sector.
    I calculated the area of a circular sector, I wanted to ask if we could see this area.

    area1 = ((60.0 * 3142 * ((radius1) ^ 2)) / (360));
                   (angle * pi * radius ^ 2) / (360)

    can view the area1?

     
  • Craig Reynolds

    Craig Reynolds - 2010-02-21

    Do you want to see the area you compute in text form, "printed" as a number on the display?  The example in OneTurning.cpp does that, displaying a text string like "speed: 4.7" where the number is calculated each frame (in this case its the value returned from the speed() method).

    (If I continue to misunderstand, perhaps you can find a friend to help translate your questions into English?)

     
  • Dany

    Dany - 2010-02-21

    I would like to see the area of the circular sector.
    Just as in this picture:

    http://upload.wikimedia.org/wikipedia/commons/d/da/Circle_arc.svg

     
  • Dany

    Dany - 2010-02-21

    The green area is the circular sector that I want to see

     
  • Craig Reynolds

    Craig Reynolds - 2010-02-21

    ddevivo87 wrote:
    > I would like to see the area of the circular sector.
    > Just as in this picture:
    > http://upload.wikimedia.org/wikipedia/commons/d/da/Circle_arc.svg

    Aha!  Again this is not tested, but you might be able to get that effect by making a modified copy of drawXZArc (from Draw.cpp), say your new function is called drawXZFilledSector.  If you change GL_LINE_STRIP to GL_TRIANGLE_FAN that may be all that is required.  Try it and let me know.  Basically, instead of drawing lines (chords) along the arc, you want to draw triangles connecting each chord to the center of the arc.

    (This already happens in drawCircleOrDisk.  Sorry it has complicated arguments, it is meant to be an internal routine.  When "filled" is true it draws a disk, when "in3d" is false it will be drawn on the ground (X-Z) plane (and "axis" is ignored).  Instead of writing drawXZArc inline perhaps I should have generalized drawCircleOrDisk to take an arc angle to replace "2*OPENSTEER_M_PI" meaning 360 degrees.)

     

Log in to post a comment.

MongoDB Logo MongoDB