中点画椭圆算法
中点圆算法 (Midpoint circle Algorithm)
This is an algorithm which is used to calculate the entire perimeter points of a circle in a first octant so that the points of the other octant can be taken easily as they are mirror points; this is due to circle property as it is symmetric about its center.
这是一种算法,用于计算第一个八分圆中一个圆的整个周边点,以便可以轻松地将另一个八分圆的点视为镜像点; 这是由于圆的属性有关它的中心对称。

In this algorithm decision parameter is based on a circle equation. As we know that the equation of a circle is x2 +y2 =r2 when the centre is (0, 0).
在该算法中,决策参数基于圆方程。 众所周知,当中心为(0,0)时,圆的方程为x 2 + y 2 = r 2 。
Now let us define the function of a circle i.e.: fcircle(x,y)= x2 +y2 - r2
现在让我们定义一个圆的函数,即: fcircle(x,y)= x 2 + y 2 -r 2
If fcircle < 0 then x, y is inside the circle boundary.
如果fcircle <0,则x , y在圆边界之内。
If fcircle > 0 then x, y is outside the circle boundary.
如果fcircle> 0,则x , y在圆边界之外。
If fcircle = 0 then x, y is on the circle boundary.
如果fcircle = 0,则x , y在圆边界上。
决策参数 (Decision parameter)
pk =fcircle(xk+1,yk-1/2) where pk is a decision parameter and in this ½ is taken because it is a midpoint value through which it is easy to calculate value of yk and yk-1.
p k = fcircle(x k + 1 ,y k-1 / 2 ) ,其中p k是决策参数,在此1/2中采用p k是因为它是一个中点值,通过该中点值很容易计算y k和y k -1 。
I.e. pk= (xk+1)2+ (yk-1/2)2-r2
即p k =(x k + 1 ) 2 +(y k-1 / 2 ) 2 -r 2
If pk <0 then midpoint is inside the circle in this condition we select y is yk otherwise we will select next y as yk-1 for the condition of pk > 0.
如果p k <0,则在这种情况下中点在圆内,我们选择y为y k,否则对于p k > 0的情况,我们将下一个y选择为y k-1 。
结论 (Conclusion)
If pk < 0 then yk+1=yk, by this the plotting points will be ( xk+1 ,yk). By this the value for the next point will be given as:
如果p k <0,则y k + 1 = y k ,由此绘制点将为(x k + 1 ,y k ) 。 这样,下一点的值将为:
Pk+1=pk +2(xk+1) +1
P k + 1 = p k +2(x k + 1 )+1
If pk > 0 then yk+1=yk-1, by this the plotting points will be (xk+1, yk-1). By this the value of the next point will be given as:
如果p k > 0,则y k + 1 = y k-1 ,由此绘制点将为(x k + 1 ,y k-1 ) 。 这样,下一点的值将为:
Pk+1=pk+2(xk+1) +1-2(yk+1)
P k + 1 = p k +2(x k + 1 )+ 1-2(y k + 1 )
初始决策参数 (Initial decision parameter)
P0 = fcircle (1, r-1/2)
P 0 =圆(1,r-1 / 2)
This is taken because of (x0, y0) = (0, r)
这是因为(x 0 ,y 0 )=(0,r)
i.e. p0 =5/4-r or 1-r, (1-r will be taken if r is integer)
即p 0 = 5 / 4-r或1-r ,(如果r为整数则采用1-r )
算法 (ALGORITHM)
In this the input radius r is there with a centre (xc , yc). To obtain the first point m the circumference of a circle is centered on the origin as (x0,y0) = (0,r).
在此,输入半径r以一个中心(x c ,y c )为中心。 为了获得第一个点m ,圆的圆周以(x 0 ,y 0 )=(0,r)为中心 。
Calculate the initial decision parameters which are:
计算初始决策参数为:
p0 =5/4-r or 1-r
p 0 = 5 / 4-r或1-r
Now at each xk position starting k=0, perform the following task.
现在,在从k = 0开始的每个x k位置,执行以下任务。
if
如果
pk < 0 then plotting point will be ( xk+1 ,yk) and
p k <0,则绘图点将为(x k + 1 ,y k )并且
Pk+1=pk +2(xk+1) +1
P k + 1 = p k +2(x k + 1 )+1
else the next point along the circle is (x
否则沿圆的下一个点是[x
k+1, yk-1) and
k + 1 ,y k-1 )和
Pk+1=pk+2(xk+1) +1-2(yk+1)
P k + 1 = p k +2(x k + 1 )+ 1-2(y k + 1 )
Determine the symmetry points in the other quadrants.
确定其他象限中的对称点。
Now move at each point by the given centre that is:
现在按照给定的中心在每个点处移动:
x=x+xc
x = x + x c
y=y+yc
y = y + y c
At last repeat steps from 3 to 5 until the condition x>=y.
最后重复步骤3到5,直到条件x> = y为止。
翻译自: https://www.includehelp.com/algorithms/midpoint-circle.aspx
中点画椭圆算法