Mid-point Ellipse algorithm is used to draw an ellipse in computer graphics.
Midpoint ellipse algorithm plots(finds) points of an ellipse on the first quadrant by dividing the quadrant into two regions.
Each point(x, y) is then projected into other three quadrants (-x, y), (x, -y), (-x, -y) i.e. it uses 4-way symmetry.
Function of ellipse:
fellipse(x, y)=ry2x2+rx2y2-rx2ry2
fellipse(x, y)<0 then (x, y) is inside the ellipse.
fellipse(x, y)>0 then (x, y) is outside the ellipse.
fellipse(x, y)=0 then (x, y) is on the ellipse.
Decision parameter:
Initially, we have two decision parameters p10 in region 1 and p20 in region 2.
These parameters are defined as : p10 in region 1 is given as :
p10=ry2+1/4rx2-rx2ry
Mid-Point Ellipse Algorithm :
- Take input radius along x axis and y axis and obtain center of ellipse.
- Initially, we assume ellipse to be centered at origin and the first point as : (x, y0)= (0, ry).
- Obtain the initial decision parameter for region 1 as: p10=ry2+1/4rx2-rx 2ry
- For every xk position in region 1 :
If p1k<0 then the next point along the is (xk+1 , yk) and p1k+1=p1k+2ry2xk+1+ry2
Else, the next point is (xk+1, yk-1 )
And p1k+1=p1k+2ry2xk+1 – 2rx2yk+1+ry2 - Obtain the initial value in region 2 using the last point (x0, y0) of region 1 as: p20=ry2(x0+1/2)2+rx2 (y0-1)2-rx2ry2
- At each yk in region 2 starting at k =0 perform the following task.
If p2k>0 the next point is (xk, yk-1) and p2k+1=p2k-2rx2yk+1+rx2
- Else, the next point is (xk+1, yk -1) and p2k+1=p2k+2ry2xk+1 -2rx2yk+1+rx2
- Now obtain the symmetric points in the three quadrants and plot the coordinate value as: x=x+xc, y=y+yc
- Repeat the steps for region 1 until 2ry2x>=2rx2y