Board index » delphi » painting circle and pieces
Pascal Schmidt-Volkmar
![]() Delphi Developer |
Pascal Schmidt-Volkmar
![]() Delphi Developer |
painting circle and pieces2004-01-30 05:10:19 PM delphi82 Hi there, I would like to paint a circle and a dynamic number of lines from its middle to the circle so it looks like a cake that has been cut into the dynamic number of pieces. How could this be done? To start with, I divide the 360?of the circle with the number of pieces. But how do I draw the lines to the "border" of the circle? Thanks! Pascal |
Pascal Schmidt-Volkmar
![]() Delphi Developer |
2004-01-30 06:55:21 PM
Re:painting circle and pieces
OK, I have managed to get this far:
r:=ROUND(Flaeche.Height/2); x0:=ROUND(Flaeche.Width/2); y0:=ROUND(Flaeche.Height/2); alpha:=ROUND(360/fDatenmodul.dsFaktoren.recordcount); for i:=0 to fDatenmodul.dsFaktoren.recordcount do begin Canvas.MoveTo(x0,y0); canvas.Pen.Width:=3; canvas.Pen.Color:=clBlack; case (i*alpha) of 0..90 : begin x1:=x0+ROUND(sin(i*alpha)*r); y1:=y0-ROUND(cos(i*alpha)*r); end; 91..180 : begin x1:=x0-ROUND(sin(i*alpha)*r); y1:=ROUND(cos(i*alpha)*r)+y0; end; 181..270 : begin x1:=x0-ROUND(sin(i*alpha)*r); y1:=y0-ROUND(cos(i*alpha)*r); end; 271..360 : begin x1:=x0+ROUND(sin(i*alpha)*r); y1:=y0-ROUND(cos(i*alpha)*r); end; end; Unfortunately, the lines are not exact where I am expecting them. There must be an error in my algorithm... Where?? Thanks, Pascal |
Alfred ten Hoeve
![]() Delphi Developer |
2004-01-30 08:43:06 PM
Re:painting circle and pieces
The goniometric functions need radians as input.
x0 := x0 + round(r * sin(i * alpha * PI / 360)); etc. Alfred. |