计算机图形学所学的算法_计算机图形学中点圆算法

计算机图形学所学的算法

什么是圆? (What is a circle?)

A circle is defined as a set of points that all are the same distance from a common point known as the center and the distance from the center of the circle to any point on its circumference is called a radius.

圆定义为一组点,这些点与一个称为中心的公共点的距离都相同,并且从圆的中心到圆周上任何点的距离都称为半径。

It is an eight-way symmetric figure which can be divided into four quadrants and each quadrant has two octants. This symmetry helps in the implementation of any circle drawing algorithm.

它是一个八向对称图形,可以分为四个象限,每个象限有两个八分之一。 这种对称性有助于实现任何圆图绘制算法。

中点圆图绘制算法简介 (Introduction to Mid-Point Circle Drawing Algorithm)

In computer graphics, the mid-point circle drawing algorithm is used to calculate all the perimeter points of a circle. In this algorithm, the mid-point between the two pixels is calculated which helps in calculating the decision parameter.

在计算机图形学中, 中点圆图绘制算法用于计算圆的所有周边点。 在该算法中,计算两个像素之间的中点,这有助于计算决策参数。

The value of the decision parameter will decide which pixel should be chosen for drawing the circle.

决策参数的值将决定应选择哪个像素来绘制圆。

This algorithm only calculates the points for one octant and the points for other octants are generated using the eight-way symmetry for the circle.

此算法仅计算一个八分圆的点,而其他八分圆的点是使用圆的八向对称性生成的。

中点圆图绘制算法的工作 (Working of the Mid-Point Circle Drawing Algorithm)

The algorithm works in the following way:

该算法以以下方式工作:

Suppose a mid-point with coordinates (x', y') is put in the general equation of the circle is

假设将具有坐标(x',y')的中点放在圆的通用方程中

    x2 + y2 - r2 = 0

gives these three values,

给出这三个值,

  • If 0 : the given point lies on the circle boundary, then any pixel can be chosen.

    如果0 :给定点位于圆边界上,则可以选择任何像素。

  • If < 0 : the given point lies inside the circle boundary, then the upper pixel can be chosen.

    如果<0 :给定点位于圆边界之内,则可以选择上方像素。

  • If > 0 : the given point lies outside the circle boundary, then the lower pixel is chosen.

    如果> 0 :给定点位于圆边界之外,则选择较低的像素。

Let there be two pixels:

设两个像素:

One pixel which is outside (A), and the other pixel which is inside (B) the circle boundary,

圆边界( A )外侧的一个像素,圆边界( B )内侧( B )的另一个像素,

Let their coordinates be:

使其坐标为:

    For A: (xk+1, yk) 
    and
    For B: (xk+1, yk-1)

Derivation

推导

Then, the co-ordinates of mid-point be

然后,中点的坐标为

MP= [((xk+1+xk+1)/2) , ((yk+yk-1) /2)]

M P = [((x k + 1 + x k +1)/ 2),((y k + y k -1)/ 2)]

(xk +1 , yk-1 / 2)

(x k +1,y k -1 / 2)

Now, put MP in the equation of circle x2 + y2 - r2 = 0

现在,将M P放入圆x 2 + y 2 -r 2 = 0的方程中

(xk +1 )2 + (yk-1 / 2)2 - r2

(x k +1) 2 +(y k -1 / 2) 2 -r 2

Let us define this equation as the decision parameter, using the mid-point MP:

让我们使用中点M P将该方程定义为决策参数:

Pk = ( xk+1 )2 + ( yk-1 / 2 )2 - r2                                                              -----(1)

P k =(x k +1) 2 +(y k -1 / 2) 2 -r 2 -----(1)

 Let us define the successive decision parameter, Pk+1:

让我们定义连续决策参数P k + 1

Pk+1 = ( xk+1 + 1 )2 + ( yk+1-1 / 2 )2 - r2                                                  -----(2)

P k + 1 =(x k + 1 +1) 2 +(y k + 1 -1 / 2) 2 -r 2 -----(2)

Subtracting eq.(1) from eq.(2);

从等式(2)中减去等式(1);

Pk+1- Pk = ( xk+1+1 )2 + ( yk+1-1 / 2 )2- r2 - [ (xk+1)2 + ( yk-1 /2 )2 - r2]

P k + 1 -P k =(x k + 1 +1) 2 +(y k + 1 -1 / 2) 2 -r 2 -[(x k +1) 2 +(y k -1 / 2) 2 -r 2 ]

Now put xk+1 = xk+1

现在把x k + 1 = x k +1

             = (xk+1 + 1)2 + (yk+1-1 / 2)2 - r2 - [ (xk+1)2 + (yk-1 / 2)2 - r2 ]

=(x k + 1 +1) 2 +(y k + 1 -1 / 2) 2 -r 2 -[(x k +1) 2 +(y k -1 / 2) 2 -r 2 ]

             = (xk+1 + 1)2 - (xk+1)2 + ( yk+1-1 / 2 )2- ( yk-1 / 2 )2

=(x k + 1 +1) 2- (x k +1) 2 +(y k + 1 -1 / 2) 2- (y k -1 / 2) 2

 Pk+1= Pk + 2xk +3 + (yk+1)2 – yk+1- (yk)2 + yk

P k + 1 = P k + 2x k +3 +(y k + 1 ) 2 – y k + 1- (y k ) 2 + y k

If Pk < 0:           yk+1 =  yk                (choose point A)

如果P k <0:y k + 1 = y k (选择点A)

Pk+1= Pk+ 2xk + 3

P k + 1 = P k + 2x k + 3

If Pk > 0:           yk+1 = yk - 1     (choose point B)                                                      

如果P k > 0:y k +1 = y k -1(选择点B)  

Pk+1 = Pk + 2xk + 2yk + 5

P k + 1 = P k + 2x k + 2y k + 5

Let us calculate the initial decision parameter (P0) where the initial points will be defined as (0, r) [which is the first point to be plotted of the first octant].

让我们计算初始决策参数(P 0 ),其中初始点将定义为(0,r)[这是要绘制的第一个八分点的第一个点]。

On putting these coordinates in eq. (1) in place of xk and yk, we get:

在把这些坐标放在等式中。 (1)代替x k和y k ,我们得到:

P0= ( 0 + 1 )2 + ( r-1 / 2 )2 - r2
P0 = 5/4 - r

P 0 =(0 + 1) 2 +(r-1 / 2) 2 -r 2
P 0 = 5/4-r

If r is an integer:
P0 = 1 - r

如果r是整数:
P 0 = 1-r

If r is a floating point:
P0 = 5/4 - r

如果r是一个浮点数:
P 0 = 5/4-r

中点圆图绘制算法 (The Mid-Point Circle Drawing Algorithm)

Step 1: Start.

步骤1:开始。

Step 2: Declare x, y, r, xc , yc , P as variables, where (xc , yc) are coordinates of the center.

步骤2:声明X,Y,R,X C,Y C,P为变量,其中(x C,Y c)是中心的坐标。

Step 3: Put x = 0 and y = r

步骤3:输入x = 0和y = r

Step 4: Repeat the steps while x ≤ y;

步骤4:在x≤y时重复步骤;

Step 5: Plot (x, y).

步骤5:绘制(x,y)。

Step 6: if (P < 0):

步骤6:如果(P <0):

                 Set P = P + 2x + 3

设定P = P + 2x + 3

             else if (P >= 0):

否则(P> = 0):

                  Set P = P + 2(x-y) + 5

设定P = P + 2(xy)+ 5

                   y = y - 1

y = y-1

 Step 7: Do x = x + 1

步骤7:x = x + 1

Step 8: End

步骤8:结束

Formulas used:

使用的公式:

For Pk < 0 :
Pk+1=Pk+ 2xk+3

对于P k <0:
P k + 1 = P k + 2x k +3

For Pk ≥ 0 :
Pk + 2xk+2yk+5

对于Pķ≥0:
P k + 2x k + 2y k +5

Advantages:

优点:

  • The mid-point circle algorithm is an efficient algorithm in drawing a circle.

    中点圆算法是绘制圆的有效算法。

  • The implementation of the algorithm is easy from the programmer’s point of view.

    从程序员的角度来看,该算法的实现很容易。

Disadvantages:

缺点:

  • The time consumption of this algorithm is high.

    该算法的时间消耗很高。

翻译自: https://www.includehelp.com/computer-graphics/mid-point-circle-algorithm.aspx

计算机图形学所学的算法

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值