Midpoint ellipse algorithm (bottom)
assuming that the Rx,ry and ellipse centers have been given in the integer screen coordinates, we only need incremental integers in the midpoint ellipse algorithmto determine the value of the decision parameter. IncrementalR2y ,R2xand the2r2yxand the2r2xyonly need to be evaluated at the beginning of the program. The midpoint ellipse algorithm can be generalizedinclude the following steps:
The steps of the midpoint ellipse-Garden algorithm
1. Enter the RX, Ry, and Ellipse centers (XC,YC) and get the first point on the ellipse (center at Origin):
2. Calculate the initial values for the decision parameters in Region 1:
3. At each XK location in zone 1, starting with k=0, complete the following tests: If P1k<0, the next point along the Center (0,0) of the Ellipse is (Xk+1,yk), and
Otherwise, the next point along the ellipse is (xk+1, yk-1), and
which
And until 2r2yx>=2r2xy.
4. Use the last point calculated in Area 1 (x0,y0) to calculate the initial value of the parameter in Zone 2:
5. In the area 2 at each YK location, starting from K=0, complete the following tests: If P2k>0, the next point of the Ellipse (0,0) along the center is (XK, yk-1) and
Otherwise, the next point along the ellipse is (xk+1,yk-1) and
Calculations are made using the same x and Y increments as in Region 1, until y=0.
6. Determine the symmetry points in the other three quadrants.
7. Move the computed pixel position (x, y) to the center of the (XC,YC) elliptical trajectory and draw the points by coordinate values:
Center Ellipse algorithm Drawing
Given the input ellipse parameters rx=8 and ry=6, we will give the steps of the midpoint ellipse algorithm to determine the raster pixel position on the elliptical trajectory in the first quadrant. The initial values and increments of the decision parameters are calculated as
For Region 1, the initial point of the ellipse at the origin of the center point is (x0,y0) = (0,6), the initial value of the decision parameter is
The following table lists the subsequent decision parameter values and the location of the ellipse trajectory computed using the center algorithm.
For Zone 2, the initial point is (x0,y0) = (7,3), the initial decision parameter is
The remainder of the elliptical trajectory in the first quadrant is calculated as
The following procedure gives an example of using the midpoint algorithm to display an ellipse. Elliptic Parameters Rx, Ry, Xcenter, and ycenter value of the process Ellipsemidpoint. The position on the first quadrant curve is computed and passed to the procedure ellipseplotpoints. The ellipse position in the other three quadrants is obtained using symmetry, and the ellipse color in the frame cache corresponding to these locations is set by the SetPixel program.
inline int round (const float a) {return int (a + 0.5);} /*the following procedure accepts values for a ellipse *center position and its semimajor and semimajor Axes,then *calcul Ates ellipse positions using the midpoint algorithm. */void ellipsemidpoint (int xcenter,int ycenter,int Rx, int Ry) {int Rx2 = RX * RX; int Ry2 = Ry * Ry; int twoRx2 = 2 * Rx2 ; int twoRy2 = 2 * RY2; int p; int x = 0; int y = Ry; int px = 0; int py = twoRx2 * y; void ellipseplotpoints (int, int, int, int); /*plot the initial point in each quadrant.*/ellipseplotpoints (xcenter, Ycenter, x, y); /*region 1*/p = round (Ry2-(RX2 * Ry) + (0.25 * Rx2)); while (px < py) {x + +, px + twoRy2; if (P < 0) p + = Ry2 + px;else{y--; PY-= twoRx2; p + = Ry2 + px-py; } ellipseplotpoints (Xcenter, Ycenter, x, y);} /*region 2*/p = Round (Ry2 * (x + 0.5) * (x + 0.5) + Rx2 * (y-1) * (y-1)-Rx2 * Ry2); while (Y > 0) {y--; py-= Tworx 2; if (P > 0) p + = rx2-py; else {x + +; px + = TwoRy2; p + = rx2-py + px;}Ellipseplotpoints (Xcenter, Ycenter, x, y); }}void ellipseplotpoints (int xcenter,int ycenter,int x, int y); {SetPixel (xcenter + x,ycenter + y); SetPixel (Xcenter-x,ycenter + y); SetPixel (Xcenter + x,ycenter-y); SetPixel (XCENTER-X,YCENTER-Y); }
Computer Graphics (ii) output element _6_opengl curve function _4_ midpoint ellipse algorithm (bottom)