Algorithm for drawing filled Pie
Community Forums/General Help/Algorithm for drawing filled Pie
| ||
Hi guys! I need a function that draws a filled pie (slice of a circle). It should do this using the following parameters: Radius, StartAngle, EndAngle Also the algo must draw the shape plotting pixels (no lines!) I've already googled around and found only examples that draws unfilled pie shapes. Including the blitz codearchives. Please help! :) |
| ||
Use sin and cos to get the points you need for example:for Angle = StartAngle to EndAngle xPos = Sin( Angle ) *Radius yPos = Cos( Angle ) *Radius DrawLine( X, Y, XPos, YPos ) next Where X and Y is the center of the circle Radius is the size of the circle XPos and YPos are floats and StartAngle and EndAngle are whatever you want Angle can be a float as it gives smoother transitions if you wanted. |
| ||
Mmmmm pie. I realise this doesn't help. |
| ||
@EdzUp[GD] Thanks for your suggestion! But as stated in the first post the algorithm must draw the pie shape one pixel/interation, both shape and its fill. I cannot use lines for this. |
| ||
Here's a starter: It draws a circle, 1 pixel at a time using horizontal rows of pixels. All you have to add is, for each pixel, compute what region of pie it's in and set the associated color. Right now it's just a random color. |
| ||
Got bored / couldn't sleep E&OE ;) |
| ||
Ooh, seems I forgot the contents of your original post: |
| ||
here is an example although it would be wayyyyyy faster with opengl points |
| ||
@matibee Thanks for providing exactly what I was looking for! :) @Nate Your app reminds me of the dream I had last night after thinking about this problem for to long :D Thanks, its a good one:) I intend to use this routine for drawing lots of smaller pie shapes, with very short radius. So I put together this testapp to magnify the drawing result at smaller sizes. Im not sure if it is an float/int rouding error on my end, but the testapp shows some "artifacts" at some angles and different radius. Also I need all tiles (or pixels) overlapped by the slice to get drawed. Finally I need the routine to cope with angle wrapping . Feel free to leave any suggestions if you like :) Here is the source for the test app (blitz3d). Or you could get an exe here |