DrawArc Problem (Or It's My Math?)

Hello NG,

      I am trying to use the Double Buffered demo in the Wiki just to draw
some simple shapes. At the moment, I'm trying to draw a circle arc, without
big success. In the simple app I attach at the end of the mail, the
relevant part is the function Draw() in the DrawWindow class. This is what
I do:

1) I first plot a circle with center (centerX, centerY) and radius =
radius;
2) Next I plot an arc of circle, that should span a 240 degrees angle.

If my math is correct, the arc should be super-imposed to the circle (they
have the same radius), but I end up with the arc that has a smaller radius
than the circle, as you may see in trying the demo. Noting that I am not an
expert on wx.DC and friends, does anyone know what I'm doing wrong?

Thanks for every suggestion.

Andrea.

(See attached file: MyArc.py)

MyArc.py (4.9 KB)

···

_______________________________________________
Andrea Gavana
Reservoir Engineer
MOGI ? Reservoir Characterization and Modeling Dept.
ENI S.p.A. ? Exploration & Production Division
Via Emilia, 1 ? 20097 San Donato Milanese (MI) ? Italy
Phone: +39 02 520 62972
Fax: +39 02 520 61824
E-mail: andrea.gavana@agip.it
Restyled Internet Site: http://xoomer.virgilio.it/infinity77/
____________________________________________________

Eni S.p.A.
Sede legale in Roma,
Piazzale Enrico Mattei 1, 00144 Roma
Tel. centralino: +39 06598.21
www.eni.it
Capitale sociale € 4.002.934.326 i.v.
Registro Imprese di Roma,
Codice Fiscale 00484960588
Part. IVA 00905811006
R.E.A. Roma n. 756453

------------------------------------------------------------------------------------------------------------------------------------------
Message for the recipient only, if received in error, please notify the
sender and read http://www.eni.it/disclaimer/

Hello NG,

     I am trying to use the Double Buffered demo in the Wiki just to draw
some simple shapes. At the moment, I'm trying to draw a circle arc, without
big success. In the simple app I attach at the end of the mail, the
relevant part is the function Draw() in the DrawWindow class. This is what
I do:

1) I first plot a circle with center (centerX, centerY) and radius =
radius;
2) Next I plot an arc of circle, that should span a 240 degrees angle.

If my math is correct, the arc should be super-imposed to the circle (they
have the same radius), but I end up with the arc that has a smaller radius
than the circle, as you may see in trying the demo. Noting that I am not an
expert on wx.DC and friends, does anyone know what I'm doing wrong?

Thanks for every suggestion.

I think it's your math. If you change the relevant lines to

        xstart = centerX + radius * math.cos(math.pi/6.0)
        xend = centerX - radius * math.cos(math.pi/6.0)
        ystart = centerY + radius * math.sin(math.pi/6.0)
        yend = ystart

then it does what (I think) you want.

You were multiplying each of those offsets by "math.cos(math.pi/6)" for no reason I can see.

I see that the arc is drawn just "within" the circle ( I changed the pen for the arc to "BLUE" to check this) - that seems to be caused by rounding on the math - I changed it again to

        xstart = centerX + radius * math.cos(math.pi/4.0) + 0.5
        xend = centerX - radius * math.cos(math.pi/4.0) + 0.5
        ystart = centerY + radius * math.sin(math.pi/4.0) + 0.5
        yend = ystart

and then the blue outline exactly overwrote the green circle.

···

andrea.gavana@agip.it wrote:

--
Alex Tweedly http://www.tweedly.net

--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.344 / Virus Database: 267.11.1/104 - Release Date: 16/09/2005