Algorithm series (11) Circle generation algorithm

Source: Internet
Author: User
Tags square root

In Plane analytic geometry, the equation of the circle can be described as (x–x0) 2 + (y–y0) 2 = R2, where (x0, y0) is the center of the coordinates, R is the radius of the circle, in particular, when (x0, y0) is the coordinate center point, the circle equation can be reduced to x2 + y2 = R2. In computer graphics, as well as straight lines, there are also problems in the display or output of the dot-matrix output device, so a raster scan conversion algorithm is also needed. In order to simplify, we first consider the circle of the center at the origin of the generation, for the central is not the origin of the circle, you can through the translation of coordinates to obtain the corresponding position of the circle.

Before scanning conversion, you need to understand the characteristics of a circle, that is, eight points of the circle. As shown in figure (1):

Figure (1) eight-cent symmetry of a circle

The circle at the origin of the center has four axis of symmetry x = 0, y = 0, x = y and x = y, if a little P (x,y) is known on the arc, you can get seven symmetrical points about the four symmetric axes: (x, Y), (-X, X), (-X,-y), (y, ×), (Y,-X), (-y, X) , (-y,-X), this property is called eight-point symmetry. So as long as you can draw a one-eighth of the arc, you can use the principle of symmetry to get the whole circle.

There are several easy ways to get round scan transformation, first of all, introduce the rectangular coordinates method. Known circle equation: x2 + y2 = R2, if x is taken as an argument, the Y is solved:

y =

When the circle is generated, scan the circle of One-fourth, let the independent variable x from 0 to R in unit step increments, at each step can solve the Y, and then call the point function to draw a circle point. But in doing so, the algorithm is inefficient because of the square root operation and all floating-point operations. And when X is near the R value (the center of the circle at the origin), near the point (r,0) on the circumference, because the slope of the circle tends to infinity, because the floating-point number rounding needs rounding, so that the circumference has a larger gap. Next, we introduce the polar coordinate method, assuming that the angle between a point P (x,y) and the x axis in the rectangular coordinate system is θ, the polar equation of the circle is:

x = rcosθ

y = rsinθ

The circle is generated by the eight-point symmetry of the circle, so that the value range of the independent variable θ (0,45°) can be used to draw the whole circle. This method involves trigonometric functions calculation and multiplication operation, and has a large computational load. Both the Cartesian and polar coordinate methods are not efficient algorithms, so they are only existed as theoretical methods, and they are not used in computer graphics to generate circles. The following is a brief introduction to some of the more useful circle generation algorithms in computer graphics.

1. Circle method of Midpoint drawing

The first is the midpoint of the circle method, considering the center at the origin, radius of the circle of R in the first quadrant of the one-eighth arc, from point (0, R) points (r/, r/) clockwise direction to determine this arc. Assuming that a point pi (xi, Yi) is already the closest point to the actual arc on the arc, the next point of Pi may only be one of the P1 or lower-right P2 on the right-hand side, as shown in Figure (2):

Figure (2) example of the dotted line method

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.