06-07-2012, 03:47 PM
MIDPOINT ELLIPSE DRAWING ALGORITHM
To write a C program to draw an ellipse using midpoint ellipse algorithm.
Algorithm
Step 1: Input radius rx, ry and ellipse center (Xc, Yc) and obtain the first point on the circumference of a circle centered on the origin as (X0, Y0) = (0, ry)
Step 2: Calculate the initial values of the decision parameter in region 1 as
P10 = r2y – r2x ry + 1/4 r2x
Step 3: At each Xk position in region 1, starting at k = 0, perform the following test:
If P1k < 0, the next point to plot is (Xk+1, Yk) and
P1k+1 = P1k+2 r2yXk+1 + r2y
Otherwise the next point is (Xk+1, Yk-1) and
P1k+1 = P1k+2 r2yXk+1 - 2r2xYk+1 + r2y
With
2 r2yXk+1=2 r2yXk+ 2r2y
2r2xYk+1=2r2xYk- 2r2x
Step 4: Calculate the initial values of the decision parameter in region 2 as
P20 = r2y(X0+1/2)2+ r2x(Y0 – 1)2- r2x r2y
Step 5: At each position starting at Yk position in region 2, starting at k = 0,
perform the following test:
If P2k > 0, the next point to plot is (Xk, Yk-1) and
P2k+1 = P2k - 2 r2yYk+1 + r2x
Otherwise the next point is (Xk+1, Yk-1) and
P2k+1 = P2k - 2 r2yXk+1 - 2r2xYk+1 + r2x
Step 6: Determine symmetry points in the other three octants
Step 7: Move each pixel position(X, Y) onto the circular path centered on
(Xc, Yc) and plot the coordinate values as
X = X + Xc Y = Y + Yc
Step 8: Repeat steps for region 1 until 2 r2yX>=2 r2xY