Bresenham Circle Algorithm

Source: Internet
Author: User

The midpoint circle algorithm takes the unit interval in one direction. The value in the other direction is determined by the distance between the midpoint of the two possible values and the circle. In actual processing, the decision variable symbol is used to determine the pixel point selection, so the algorithm is more efficient.

1. MidPoint Circle Algorithm Description

Set the center of the circle to be displayed to be at the origin (0, 0), the radius to R, the start point to (0, R), the end point to (,), and 1/8 circles clockwise, use symmetric scan to convert all circles.

To apply the MidPoint Circle Method, we define a circle function.

F (x, y) = 2 + y2-R2 (2-19)

 

The relative position of any vertex (x, y) can be detected by the symbol of the circle function:

F (x, y) <0 points (x, y) in the mathematical circle

 

= 0 (x, y) on the mathematical circle

> 0 (x, y) points out of the mathematical circle

(2-20)

 

 

As shown in the figure, there are two arcs A and B. Assume that the current point is Pi (XI, Yi). If the circle is generated clockwise, then the next point can only take the right side of the point E (XI + 1, Yi) or the right bottom of the Point Se (XI + 1, Yi-1) one of the two.

Midpoint draw Algorithm

Assume that m is the midpoint of E and Se, that is, 1. When F (m) <0, M is in the circle (arc ), this indicates that point E is closer to the circle, and point E should be taken as the next pixel point;

2. When F (m)> 0, M is outside the circle (arc B), indicating that the se point is closer to the Circle and the se point should be taken;

3. When F (m) = 0, you can just take one of the points E and Se. We agree to get the point se.

Ii. Thoughts on the dot Circle Algorithm

Therefore, we use the circle function of the midpoint m as the decision variable Di, and use the increment method to calculate the decision variable di + 1 of the next midpoint M iteratively.

(2-21)

 

The derivation of the decision variable di + 1 in Iterative Computing is discussed in the following two cases.

1. See figure (a). If Di is <0, select "E", and the next vertex is. The new decision variable is:

(2-22)

 

(A) (di <0) midpoint draw Algorithm

Formula (2-22) minus (2-21:

Di + 1 = di + 2xi + 3 (2-23)

 

2. See figure (B). If Di is greater than or equal to 0, select the se point and the next midpoint. The new decision variable is:

(2-24)

 

(B) (di ≥ 0) midpoint draw Algorithm

Formula (2-24) minus (2-21:

Di + 1 = di + 2 (Xi-yi) + 5 (2-25)

 

We use recursive iteration to calculate each point on the 1/8 arc. Each iteration requires two steps:

(1) use the symbol of the decision variable calculated in the previous iteration to determine the selected point.

(2) calculate the value of the new decision variable again based on the selected vertex.

The remaining problem is to calculate the initial decision variable D0, as shown in. For the initial point (0, R), 1/8 circles are generated clockwise, and the coordinates of m in the next midpoint are:

(2-26)

 

The initial condition for generating a circle and the generating direction of the circle

3. Implementation of the MidPoint Circle Algorithm

1. Input: circle radius R, center (x0, y0 );

2. determine the initial values: x = 0, y = R, D = 5/4-R;

3. While (x <= y)

{

· Draw eight pixel points (x, y) with the specified color based on the eight-point symmetry );

· If D is greater than or equal to 0

{

Y = Y-1; // wind: I personally think this sentence should be placed in the next sentence

D = d + 2 (x-y) + 5 );

}

Otherwise

D = d + 2x + 3;

· X = x + 1;

}

5. Improved MidPoint Circle Algorithm

In the preceding algorithm, floating point numbers are used to represent the decision variable D. To simplify the algorithm and get rid of floating point numbers, we use all integers in the algorithm. E = D-1/4 is used to replace D. Obviously, the initial value D = 5/4-r corresponds to E = 1-r. The decision variable d <0 corresponds to E <-1/4. Other D-related formulas in the algorithm can replace d with E directly. E is always an integer because the initial value of E is an integer and the iteration value during the operation is also an integer. Therefore, e <-1/4 is equivalent to E <0. Therefore, you can write the dot circle algorithm that is fully implemented using integers.

Requirement: Write the dot circle algorithm program implemented by integers, debug the program on the computer, and view the running results.

Vi. MidPoint Circle Algorithm Program

 

 

Void midpointcircle (INT x0, int y0, int R, int color)

{

Int X, Y;

Float D;

X = 0;

Y = R;

D = 5.0/4-r;

While (x <= y)

{

Putdot (x0, y0, X, Y, color );

If (d <0)

D + = x * 2.0 + 3;

Else

{

D ++ = 2.0 * (x-y) + 5;

Y --;

}

X ++;

}

}

Putdot (x0, y0, X, Y, color)

{

Putpixel (x0 + X, y0 + Y, color );

Putpixel (x0 + X, y0-y, color );

Putpixel (x0-x, y0 + Y, color );

Putpixel (x0-x, y0-y, color );

Putpixel (x0 + Y, y0 + X, color );

Putpixel (x0 + Y, y0-x, color );

Putpixel (x0-y, y0 + X, color );

Putpixel (x0-y, y0-x, color );

}

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.