绘制圆弧的有效算法? [英] efficient algorithm for drawing circle arcs?

查看:487
本文介绍了绘制圆弧的有效算法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用中点圆算法(布雷森汉姆圆)有效地绘制整个圆。是否有类似画圆弧的东西?我想指定开始角度和结束角度,并且只画出圆的那一部分。



预先感谢!



编辑:我也想绘制实心圆弧,即扇形切片。 :)

解决方案

您的平台上是否没有用于处理此类形状的库?



绘制一个填充的饼图:



首先,将饼图垂直和水平切割成四分之一。
如果您的饼图恰好是这些区域之一,或者完全适合这些区域之一,则请使用以下过程一次。
否则,您的饼片会被切成碎片-即使对于某些非常薄的饼片拼接也可能会发生这种情况-每片都重复以下操作。



我将描述一个适合于右上角的饼图,其他两个部分相似。
查找弧的开始和结束像素(这可能需要一些触发)。
我假设右上角该弧的开始像素是结束像素左上方的那个像素-如果不是,请交换它们以使其成为这样。

使用Bresenham圆算法从顶部开始在圆四分之一的边缘上找到所有像素。忽略这些值,直到到达开始像素为止–活动像素是圆边缘上从开始像素到结束像素的点。



使用布雷森汉姆线算法在左线上找到像素(该线从弧的开始像素开始,然后一直直线到圆心)。



对于弧的每条扫描线(每个y值),绘制一条水平线以覆盖从弧的最左像素到最活动的像素的所有水平像素。
(在四分之一圆的顶部附近,边缘上可能有许多像素处于相同的扫描线y值)



一次您已经处理了圆框边缘中的所有活动像素,
会填充剩余的三角形(如果有)。
一种方法:
对于每条扫描线(每个y值),从上到下绘制一条水平线,以覆盖从左行的最左像素到最右像素的所有水平像素。右线的
,直到到达圆心为止。
(如果起始像素位于该四分之一圆的底部附近,则左行和右行上可能有许多像素处于相同的扫描线y值)。


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 like to draw filled circle arcs too, i.e pie-slices. :)

解决方案

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).

这篇关于绘制圆弧的有效算法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆