Computer Graphics (ii) output element _6_opengl curve function _4_ midpoint ellipse algorithm (upper)

Source: Internet
Author: User

Midpoint ellipse algorithm (top)

The method here is similar to displaying a raster circle. Given the parameters Rx,ry and (XC,YC), first determine the point (x, y) on the standard position ellipse centered on the origin, and then translate the points to an ellipse centered on (XC,YC). If you want to display an ellipse that is not in the standard position, rotate around the center coordinate and redirect the long and short axes. But currently only the ellipse showing the standard position is considered, the 4th chapter will discuss the general method of transforming object direction and position.

The midpoint ellipse algorithm is divided into two parts to be applied to the first quadrant. Figure 3.25 shows the division of the first quadrant based on the elliptic slope of the rx<ry. This quadrant is processed by taking the unit step in the x direction in the area where the slope absolute value is less than 1, and by taking the unit step in the Y direction in the area where the absolute slope value is greater than 1.


Zone 1 and Region 2 (see figure 3.25) can be processed in a variety of ways. You can start with a position (0,ry), step clockwise along an elliptical path in the first quadrant, and convert the unit stride in x direction to the unit stride in the y direction when the slope becomes less than 1. Conversely, you can also start with (rx,0), select the point counterclockwise, and when the slope is greater than-1, change the unit step in the Y direction to the unit step in the x direction. With a parallel processor, you can calculate pixel locations in two regions at the same time. As an example of the serial implementation of the midpoint ellipse algorithm, the (0>ry) is used as the starting point to step clockwise along the elliptical path within the first quadrant.

In equation (3.37), Take (XC, YC) = (0 > 0), define the ellipse function as


The function has the following characteristics:

Therefore, the Elliptic function fellipse (x, y) as the decision parameter of the midpoint algorithm. At each sampling location, the next pixel is selected according to the symbol of the midpoint between the ellipse function and the two candidate pixels along the ellipse trajectory. Starting at (0, Ry), take the unit step in the x direction between the line 1 and the boundary between area 2 (see Figure 3.25), then convert the unit step in the Y direction, and then cover the remaining curve segments in the first quadrant. In each step, you need to detect the slope value of the curve.

The slope of the ellipse can be calculated from equation (3.39):

At the junction of Region 1 and Zone 2, dy/dx-1, and

Therefore, the condition for removing zone 1 is

Figure 3.26 gives the midpoint between the two candidate pixels at the sampling position xk+l in the first quadrant. If you select a position (Xk,yk) in the previous step, you can evaluate the decision parameter (that is, the ellipse function (3.39)) by the midpoint to determine the next position along the elliptical trajectory:

If p1k<0, then the midpoint is inside the ellipse, and the pixels on the yk of the scan line are closer to the ellipse boundary. Otherwise, the midpoint is outside the ellipse, or on the ellipse boundary, the selected pixel should be on the scan line yk-1.

At the next sampling location (xk+1+1= xk+2), the decision parameters for Region 1 can be evaluated as

Or

Wherein, yk+1 according to the p1k symbol value is YK or, yk-1

The decision parameters are incremented in the following increments:

As with the circle algorithm, the increment calculation of decision parameters only needs to use the addition and subtraction operation, because the values of 2r2yx and 2r2xy can also be obtained by increment. At the starting position (0, Ry), these two items can be calculated as

When x and y increment, the value is updated by adding the equation (3.45) plus 2r2xy and subtracting the equation (3.46) from the 2r2yx. The update values for each step are compared, and when the condition (3.42) is met, the Zone 1 is shifted from Region 2. In Region 1, the initial value of the decision parameter can be obtained by the Ellipse function at the starting point (xo,yo) = (0,ry):

Or

In Region 2, the unit step is sampled in the negative Y direction. Each step calculates and obtains the midpoint between the horizontal pixels (see figure 3.27). For this region, the decision parameters are evaluated as


If p2k> 0, the midpoint is outside the ellipse boundary, the pixel at XK is selected, and if p2k< = 0, the midpoint is within or above the ellipse boundary, we select the pixel at xk+1.

In order to determine the relationship between successive decision parameters in Zone 2, we are at the next sampling step yk+1-1 = yk-2 to the elliptic function

Evaluation:

Or

Where the xk+1 is set according to the P2K symbol the desirable value is XK or xk+1.

When entering Zone 2 o'clock, its initial point (X0,Y0) is the last position selected in Region 1, then the initial decision parameter of Region 2 is

To simplify the P20. , select the pixel position in the clockwise direction from the recognition (rx,0). The unit step is then taken in the positive y direction until the last position selected in Region 1.

By using the equation (3.36) and calculating the pixel position of the entire elliptical trajectory, the midpoint algorithm can be applied to the ellipse that produces the nonstandard position. In addition, the transformation method discussed later redirects the ellipse axis to the standard position, applies the midpoint algorithm to determine the position of the curve, and then converts the calculated pixel position to the position along the original ellipse trajectory.

Computer Graphics (ii) output element _6_opengl curve function _4_ midpoint ellipse algorithm (upper)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.