计算机图形学椭圆
什么是椭圆形? (What is an ellipse?)
Ellipse is defined as the geometric figure which is the set of all points on a plane whose distance from two fixed points known as the foci remains a constant.
椭圆定义为几何图形,它是平面上所有点的集合,其与两个固定点(称为焦点)的距离保持恒定。
It consists of two axes: major and minor axes where the major axis is the longest diameter and minor axis is the shortest diameter.
它由两个轴组成:长轴和短轴,其中长轴是最长的直径,短轴是最短的直径。
Unlike circle, the ellipse has four-way symmetry property which means that only the quadrants are symmetric while the octants are not.
与圆形不同,椭圆具有四向对称性,这意味着只有象限是对称的,而八分象不是。
Here, we will calculate the points for one quadrant while the points for the remaining three can be calculated using the former points.
在这里,我们将计算一个象限的点,而其余三个点的点可使用前一个点来计算。
中点椭圆绘图算法简介 (Introduction to the Mid-Point Ellipse Drawing Algorithm)
In computer graphics, the mid-point ellipse algorithm is an incremental method of drawing an ellipse. It is very similar to the mid-point algorithm used in the generation of a circle.
在计算机图形学中, 中点椭圆算法是绘制椭圆的增量方法。 它与生成圆时使用的中点算法非常相似。
The mid-point ellipse drawing algorithm is used to calculate all the perimeter points of an ellipse. 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 determines whether the mid-point lies inside, outside, or on the ellipse boundary and the then position of the mid-point helps in drawing the ellipse.
中点椭圆绘制算法用于计算椭圆的所有周边点。 在该算法中,计算两个像素之间的中点,这有助于计算决策参数。 决策参数的值确定中点是在椭圆边界的内部,外部还是在椭圆边界上,然后中点的位置有助于绘制椭圆。
中点椭圆绘图算法的工作 (Working of the Mid-Point Ellipse Drawing Algorithm)
Now, for understanding the proper working of the algorithm, let us consider the elliptical curve in the first quadrant.
现在,为了理解算法的正确工作,让我们考虑第一象限中的椭圆曲线。
Also, consider the equation of ellipse:
另外,考虑椭圆方程:
ry2 x2 + rx2 y2 - rx2 ry2 = 0 ...(1)
where, ry : semi-minor axis
rx : semi-major axis
In the ellipse each quadrant is divided into two regions: R1 and R2 respectively.
在椭圆中,每个象限分为两个区域:分别为R1和R2 。
We know that the slope of an ellipse is given by:
我们知道,椭圆的斜率由下式给出:
m =dx / dy = - (2 ry2 x /2 rx2 y ) = -1
The region R1 has the value of slope as m<-1 while R2 has the value of slope as m > -1.
区域R1的斜率值为m <-1,而R2的斜率值为m> -1 。
The starting point for R1 will be (0, ry) and for R2, the initial points will become the ending points of R1, where the slope becomes greater than -1. Thats why we need to keep in check the value of slope while plotting the points for R1 to know whether we have reached R2 or not.
R1的起点将是(0,r y ) , R2的起点将成为R1的终点,斜率大于-1 。 这就是为什么我们需要在绘制R1的点以了解我们是否达到R2时保持斜率的值。
We will do the derivation for each region:
我们将对每个区域进行推导:
Derivation for Region 1:
区域1的推导
Let us consider two pixels: one which is outside(A) and the other which is inside(B) respectively.
让我们考虑两个像素:一个像素位于( A )外侧,另一个像素位于( B )内侧。
Let their coordinates be:
使其坐标为:
For A; ( xk+1, yk )
为一个; (x k +1,y k )
For B; ( xk+1, yk-1 )
对于B; (x k +1,y k -1)
Value for their mid-point will 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)
Putting Mp in eqn (1):
将M p放在eqn(1)中:
ry2 (xk+1)2 + rx2 ( yk-1 / 2 )2 - rx2 ry2
r y 2 (x k +1) 2 + r x 2 (y k -1 / 2) 2 -r x 2 r y 2
Let us define this statement as our decision variable:
让我们将此语句定义为决策变量:
Pk= ry2 ( xk+1 )2 + rx2 ( yk-1 / 2 )2 - rx2 ry2 -----(2)
P k = r y 2 (x k +1) 2 + r x 2 (y k -1 / 2) 2 -r x 2 r y 2 -----(2)
Successive parameter can be defined as:
连续参数可以定义为:
Pk+1 = ry2 ( xk+1+1 )2 + rx2 ( yk+1-1 / 2 )2- rx2 ry2 -----(3)
P k + 1 = r y 2 (x k + 1 +1) 2 + r x 2 (y k + 1 -1 / 2) 2 -r x 2 r y 2 -----(3)
Now, subtract eqn (2) from eqn (3);
现在,从等式(3)中减去等式(2);
Pk+1 - Pk = [ ry2 ( xk+1 + 1 )2 + rx2 ( yk+1-1 / 2 )2- rx2 ry2 ] - [ ry2 (xk+1)2+ rx2( yk-1 / 2 )2- rx2 ry2 ]
P k + 1 -P k = [r y 2 (x k + 1 +1) 2 + r x 2 (y k + 1 -1 / 2) 2 -r x 2 r y 2 ]-[r y 2 ( x k +1) 2 + r x 2 (y k -1 / 2) 2 -r x 2 r y 2 ]
= ry2 [ (xk+1+1)2 - (xk+1)2 ] + rx2 [ ( yk+1-1 / 2 )2 - ( yk-1 / 2 )2 ]
= r y 2 [(x k + 1 +1) 2- (x k +1) 2 ] + r x 2 [(y k + 1 -1 / 2) 2- (y k -1 / 2) 2 ]
As the x-coordinate remains same in both the pixels, put xk+1 = xk+1
由于两个像素的x坐标均相同,因此将x k + 1 = x k +1
Pk+1- Pk = ry2 [ (xk+1+1)2 - (xk+1)2 ] + rx2 [ ( yk+1-1 / 2 )2 - ( yk-1 / 2)2 ]
P k + 1 -P k = r y 2 [(x k + 1 + 1) 2- (x k +1) 2 ] + r x 2 [(y k + 1 -1 / 2) 2- (y k -1 / 2) 2 ]
= ry2 [ 2xk + 3 ] + rx2 [ (yk+1)2 - yk+1 - (yk)2 + yk ]
= r y 2 [2x k + 3] + r x 2 [(y k + 1 ) 2 -y k + 1- (y k ) 2 + y k ]
Pk+1 = Pk + ry2 [ 2xk + 3 ] + rx2 [ (yk+1)2 - yk+1 - (yk)2 + yk ]
P k + 1 = P k + r y 2 [2x k + 3] + r x 2 [(y k + 1 ) 2 -y k + 1- (y k ) 2 + y k ]
If Pk < 0 : use yk+1 = yk (Choose point A)
如果P k <0:使用y k + 1 = y k (选择点A)
Pk+1 = Pk+ ry2 [ 2xk + 3 ]
P k + 1 = P k + r y 2 [2x k + 3]
If Pk ≥ 0: use yk+1 = yk -1 (Choose point B)
如果Pķ≥0:Y用K + 1 = Y K -1 (选择B点)
Pk+1 = Pk + ry2 [ 2xk + 3 ] + 2 [ 1 - yk ]
P k + 1 = P k + r y 2 [2x k + 3] + 2 [1-y k ]
Initial Decision Parameter
初始决策参数
Put initial point(0,ry) in eq.(2)
将初始点(0,r y )放在等式(2)中
P0= ry2 (0+1)2 + rx2( ry-1 /2)2 - rx2 ry2
P0 = ry2 + rx2/4 - ry rx2
P 0 = r y 2 (0 + 1) 2 + r x 2 (r y -1 / 2) 2 -r x 2 r y 2
P 0 = r y 2 + r x 2 /4-r y r x 2
Derivation for Region 2:
区域2的推导:
Let us consider two pixels: one which is outside(P) and the other which is inside(Q) respectively.
让我们考虑两个像素:一个位于外部( P ),另一个位于内部( Q )。
Let their coordinates be:
使其坐标为:
For P; (xk+1, yk-1)
对于P; (x k +1,y k -1)
For Q; (xk, yk-1)
对于Q; (x k ,y k -1)
Value for their mid-point will be:
他们的中点价值为:
Mp= [ ( (xk+1+ xk) / 2 ), ( (yk-1 yk-1) / 2 ) ]
M p = [((x k +1+ x k )/ 2),((y k -1 y k -1)/ 2)]
= ( xk+1 / 2 , yk-1 )
=(x k +1 / 2,y k -1)
Putting Mp in eq.(1):
将M p放在等式(1)中:
ry2 (xk+1 / 2)2 + rx2 (yk-1)2- rx2 ry2
r y 2 (x k +1 / 2) 2 + r x 2 (y k -1) 2 -r x 2 r y 2
Let us define this statement as our decision variable:
让我们将此语句定义为决策变量:
P2k = ry2 ( xk+1 /2)2 + rx2 (yk-1)2 - rx2 ry2 ----(4)
P2 k = r y 2 (x k +1 / 2) 2 + r x 2 (y k -1) 2 -r x 2 r y 2 ----(4)
Successive parameter can be defined as:
连续参数可以定义为:
P2k+1= ry2 ( xk+1 + 1 / 2 )2 + rx2 ( yk+1-1 )2 - rx2 ry2 ----(5)
P2 k + 1 = r y 2 (x k + 1 +1 / 2) 2 + r x 2 (y k + 1 -1) 2 -r x 2 r y 2 ----(5)
Now, subtract eq.(4) from eq.(5);
现在,从等式(5)中减去等式(4);
P2k+1- P2k = [ ry2 (xk+1+1/2)2 + rx2 (yk+1-1)2- rx2ry2 ] - [ ry2 (xk+1/2)2+ rx2 (yk-1)2 - rx2 ry2]
P2 k + 1 -P2 k = [r y 2 (x k + 1 +1/2) 2 + r x 2 (y k + 1 -1) 2 -r x 2 r y 2 ]-[r y 2 ( x k +1/2) 2 + r x 2 (y k -1) 2 -r x 2 r y 2 ]
= ry2 [ (xk+1+1 / 2 )2 - ( xk+1 / 2 )2 ] + rx2 [ (yk+1-1)2 - (yk-1)2]
= r y 2 [(x k + 1 +1 / 2) 2- (x k +1 / 2) 2 ] + r x 2 [(y k + 1 -1) 2- (y k -1) 2 ]
As the y-coordinate remains same in both the pixels, put yk+1 = yk-1
由于两个像素的y坐标均相同,因此将y k + 1 = y k -1
P2k+1- P2k = ry2 [ (xk+1)2 + xk+1 - (xk)2 - xk ]+ rx2 [ 3 - 2yk ]
P2 k + 1 -P2 k = r y 2 [(x k + 1 ) 2 + x k + 1- (x k ) 2 -x k ] + r x 2 [3-2y k ]
P2k+1 = P2k + ry2 [ (xk+1)2 + xk+1 - (xk)2 - xk ]+ rx2 [ 3 - 2yk ]
P2 k + 1 = P2 k + r y 2 [(x k + 1 ) 2 + x k + 1- (x k ) 2 -x k ] + r x 2 [3-2y k ]
If P2k > 0: use xk+1= xk (Choose point Q)
如果P2 k > 0:使用x k + 1 = x k (选择点Q)
P2k+1 = P2k - 2 yk+1 rx2 + rx2
P2 k + 1 = P2 k -2 y k + 1 r x 2 + r x 2
If P2k ≤ 0: use xk+1 = xk +1 (Choose point P)
如果P2ķ≤0:使用值 X k + 1 = X k + 1 个 (选择点P)
P2k+1 = P 2k+ 2ry2 [2 xk+1] - 2 yk+1 rx2 + rx2
P2 k + 1 = P 2 k + 2r y 2 [2 x k + 1 ]-2 y k + 1 r x 2 + r x 2
Initial Decision Parameter:
初始决策参数:
Putting the ending point of region R1
放置区域R1的终点
Where, m > -1 i.e. (x, y) in eq.(4)
其中,m> -1,即等式(4)中的(x,y)
P20 = ry2 ( x+1 / 2 )2 + rx2 (y-1)2 - rx2 ry2
P2 0 = r y 2 (x + 1/2) 2 + r x 2 (y-1) 2 -r x 2 r y 2
算法 (Algorithm)
Step 1: Start
步骤1:开始
Step 2: Declare rx , ry , x , y , m , dx , dy , P , P2.
步骤2:声明r x ,r y ,x,y,m,dx,dy,P,P2。
Step 3: Initialize initial point of region1 as
步骤3:将region1的初始点初始化为
x=0 , y = ry
x = 0,y = r y
Step 4: Calculate P= ry2 + rx2 / 4 - ry rx2
步骤4:计算P = r y 2 + r x 2 /4-r y r x 2
dx = 2 ry2 x
dx = 2 r y 2 x
dy = 2 rx2 y
dy = 2 r x 2 y
Step 5: Update values of dx and dy after each iteration.
步骤5:每次迭代后更新dx和dy的值。
Step 6: Repeat steps while (dx < dy):
步骤6:在(dx <dy)时重复步骤:
Plot (x,y)
图(x,y)
if(P < 0)
如果(P <0)
Update x = x+1 ;
更新x = x + 1;
P += ry2 [2x + 3 ]
P + = y 2 [2x + 3]
Else
其他
Update x = x + 1
更新x = x + 1
y= y - 1
y = y-1
Step 7: When dx ≥ dy, plot region 2:
步骤7:当dx≥dy时,绘制区域2:
Step 8: Calculate P2 = ry2 ( x+1 / 2)2 + rx2 (y -1)2- rx2ry2
步骤8:计算P2 = r y 2 (x + 1/2) 2 + r x 2 (y -1) 2 -r x 2 r y 2
Step 9: Repeat till (y > 0)
步骤9:重复直到(y> 0)
If (P2 > 0)
如果(P2> 0)
Update y = y-1 (x will remain same)
更新y = y-1(x将保持不变)
P2 = P2 -2 y rx2 + rx2
P2 = P2 -2年x 2 + r x 2
else
其他
x = x+1
x = x + 1
y = y-1
y = y-1
P2= P2+ 2 ry2 [2x] -2 y rx2 + rx2
P2 = P2 + 2 r y 2 [2x] -2 yr x 2 + r x 2
Step 10: End
步骤10:结束
Advantages:
优点:
The mid-point ellipse algorithm has simple and easy implementation as it only includes addition operations.
中点椭圆算法实现简单,因为它仅包含加法运算。
Disadvantages:
缺点:
This algorithm is time consuming.
该算法很耗时。
翻译自: https://www.includehelp.com/computer-graphics/mid-point-ellipse-algorithm.aspx
计算机图形学椭圆