Hi Andrea,
I think that you are not calculating correctly the start/ending points.
Try this:
def Draw(self, dc):
def rad(a): # convert deg to rad
d=a*math.pi/180
return d
size = self.GetClientSize()
if size.x < 1 or size.y < 1:
return
self.faceBitmap = wx.EmptyBitmap(size.width, size.height)
dc.BeginDrawing()
dc.SetBackground(wx.Brush("White"))
dc.Clear()
centerX = self.faceBitmap.GetWidth() / 2
centerY = self.faceBitmap.GetHeight() / 2
radius = min(centerX, centerY)
dc.SetPen(wx.Pen("GREEN", 1))
dc.DrawCircle(centerX, centerY, radius)
#Equation of a Circle: (parametric coordinates)
#for a circle with center (Xc, Yc) and radius r:
#x(t) = r cos(t) + Xc y(t) = r sin(t) + Yc
a=60 # starting angle
b=-240 # ending angle
xstart =centerX + radius*math.cos(rad(a))
ystart =centerY + radius*math.sin(rad(a))
xend = centerX + radius*math.cos(rad(b))
yend = centerY + radius*math.sin(rad(b))
dc.SetPen(wx.Pen("RED", 1))
dc.DrawArc(xstart, ystart, xend, yend, centerX, centerY)
dc.DrawText("S "+str(a),xstart, ystart)
dc.DrawText("E "+str(b),xend, yend)
dc.EndDrawing()
#AB
···
-----Original Message-----
From: andrea.gavana@agip.it [mailto:andrea.gavana@agip.it]
Sent: segunda-feira, 19 de Setembro de 2005 9:03
To: wxPython-users@lists.wxwidgets.org
Subject: [wxPython-users] 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)
_______________________________________________
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/