开发者

efficient algorithm for drawing circle arcs?

I am using the mid-point circle algorithm (bresenham circle) to efficiently draw whole circles. Is there something similar to draw circle arcs? I would like to specify a start angle and end angle and have only that portion of the circle drawn.

Thanks in advance!

EDIT: I would li开发者_如何学JAVAke to draw filled circle arcs too, i.e pie-slices. :)


Calculate the start and end point of the arc and terminate when this point has been reached. See e.g. http://en.wikipedia.org/wiki/Midpoint_circle_algorithm


Doesn't your platform already have some library that handles drawing these kinds of shapes?

Drawing a filled pie-slice:

First, cut the pie vertically and horizontally, into quarters. If your pie slice is exactly one of those quarters, or fits entirely inside one of these quarters, then use the following procedure once. Otherwise your pie slice has been cut into pieces -- this can happen even for some very skinny pie-splices -- repeat the following for each piece.

I'm going to describe a pie slice that fits in the top-right quarter -- other quarters are similar. Find the beginning and ending pixel of the arc (this may require some trig). I'm assuming the "beginning" pixel of this arc in the top-right quarter is the one higher and to the left of the "ending" pixel -- if not, swap them to make it so.

Use the Bresenham circle algorithm to find all the pixels on the rim of that quarter of the circle, starting at the top. Ignore the values until you get to the "beginning" pixel -- the "active" pixels are the points on the rim of the circle from the beginning pixel to the ending pixel.

Use the Bresenham line algorithm to find pixels on the "left" line (the line that begins at the "beginning" pixel of the arc, and goes straight to the center of the circle).

For each scan-line (each y-value) of the arc, draw one horizontal line to cover all the horizontal pixels from the leftmost pixel of the left line to the rightmost active pixel on the arc. (Near the top of the quarter-circle, there can be many pixels on the rim that are on the same scan-line y-value)

Once you've handled all the active pixels in the circle rim, fill in the remaining triangle, if any. One way: For each scan-line (each y-value), from top to bottom, draw one horizontal line to cover all the horizontal pixels from the leftmost pixel of the left line to the rightmost pixel of the right line, until you reach the center of the circle. (If the beginning pixel is near the bottom of this quarter-circle, there can be many pixels on the left line and the right line that are on the same scan-line y-value).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜