The document discusses methods for scan-converting circles and ellipses, highlighting the use of symmetry to plot points efficiently. It details two mathematical definitions for circles (polynomial and trigonometric) and outlines Bresenham's algorithm for approximating circles in raster graphics. Additionally, it explains similar methods for defining and scan-converting ellipses using both polynomial and trigonometric approaches.
Download as PPTX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
2 views
Circle Drawing Algorithm
The document discusses methods for scan-converting circles and ellipses, highlighting the use of symmetry to plot points efficiently. It details two mathematical definitions for circles (polynomial and trigonometric) and outlines Bresenham's algorithm for approximating circles in raster graphics. Additionally, it explains similar methods for defining and scan-converting ellipses using both polynomial and trigonometric approaches.
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12
Scan Converting a Circle
A circle is a symmetrical figure.
Any circle-generating algorithm can take advantage of the circle's symmetry to plot eight points for each value that the algorithm calculates. Eight-way symmetry is used by reflecting each calculated point around each 45° axis. For example, if point 1 in Fig. 3-4 were calculated with a circle algorithm, seven more points could be found by reflection. Defining a Circle There are two standard methods of mathematically defining a circle centered at the origin. The first method defines a circle with the second-order polynomial equation
y2=r2-x2
where x = the x coordinate
y = the y coordinate
r = the circle radius
With this method, each x coordinate in the sector from 90° to
45°, is found by stepping x from 0 to
r/sqrt(2), and each y coordinate is found by evaluating sqrt(r2 — x2)
for each step of x.
This is a very inefficient method, however, because for each
point both x and r must be squared and subtracted from each other; then the square root of the result must be found. Defining a Circle The second method of defining a circle makes use of trigonometric functions (see Fig. 3-6): x = r cos ɵ y = r sin ɵ where ɵ = current angle r = circle radius x = x coordinate y = y coordinate By this method, ɵ is stepped from ɵ to Π/4, and each value of x and y is calculated. However, computation of the values of sin ɵ and cos ɵ is even more time-consuming than the calculations required by the first method. Generating a circle using Polynomial Method 1. Set the initial variables: r = circle radius; (h, k) = coordinates of the circle center; x = 0; i = step size; 2. Test to determine whether the entire circle has been scan-converted. If x > xend, stop. 3. Compute the value of the y coordinate, where y = sqrt(r2 — x2). 4. Plot the eight points, found by symmetry with respect to the center (h, k), at the current (x, y) coordinates: Plot(x + h, y + k) Plot(-x + h, -y + k) Plot(y + h, x + k) Plot(-y + h, -x + k) Plot(-y + h, x + k) Plot(y + h, -x + k) Plot(-x + h, y + k) Plot(x + h, -y + k) 5. Increment x: x = x + i. 6. Go to step 2. Scan Convert a Circle using Trigonometric Method 1. Set the initial variables: r = circle radius; (h, k) = coordinates of the circle center; i = step size; ɵend = Π/4 (radians = 45°); ɵ = 0. 2. Test to determine whether the entire circle has been scan-converted. If ɵ > ɵ end , stop. 3. Compute the value of the x and y coordinates: x = r cos(ɵ) y = r sin(ɵ) 4. Plot the eight points, found by symmetry with respect to the center (h, k), at the current (x, y) coordinates: Plot(x + h, y + k) Plot(-x + h, -y + k) Plot(y + h,x + k) Plot(-y + h, -x + k) Plot(-y + h, x + k) Plot(y + h,-x + k) Plot(-x + h, y + k) Plot(x + h, -y + k) 5. Increment : ɵ = ɵ + i. 6. Go to step 2. Bresenham's Circle Algorithm Scan-converting a circle using Bresenham's algorithm works as follows. The best approximation of the true circle will be described by those pixels in the raster that fall the least distance from the true circle. Examine Fig. 3-8. Notice that, if points are generated from 90° and 45°,each new point closest to the true circle can be found by taking either of two actions: (1) move in the x direction one unit or (2) move in the x direction one unit and move in the negative y direction one unit. Therefore, a method of selecting between these two choices is all that is necessary to find the points closest to the true circle. Bresenham's Circle Algorithm Assume that (xi,yi) are the coordinates of the last scan- converted pixel upon entering step i. Let the distance from the origin to pixel T squared minus the distance to the true circle squared = D(T). Then let the distance from the origin to pixel S squared minus the distance to the true circle squared = D(S). As the coordinates of T are (xi + 1,yi) and those of S are (xi + 1,yi-1), the following expressions can be developed:
This function D provides a relative measurement of the
distance from the center of a pixel to the true circle. Since D(T) will always be positive (T is outside the true circle) and D(S) will always be negative (S is inside the true circle), a decision variable di may be defined as follows:
When di < 0, we have |D(T)| < |D(S)| and pixel T is
chosen. When di > 0, we have |D(T)| > |D(S)| and pixel S is selected. Bresenham's Circle Algorithm 1. Set the initial values of the variables: (h, k) = coordinates of circle center; x = 0; y = circle radius r and d = 3 - 2r. 2. Test to determine whether the entire circle has been scan-converted. If x > y, stop. 3. Plot the eight points, found by symmetry with respect to the center (h, k), at the current (x, y) coordinates: Plot(x + h, y + k) Plot(-x + h, -y + k) Plot(y + h, x + k) Plot(-y + h, -x + k) Plot(-y + h, x + k) Plot(y + h,-x + k) Plot(-x + h, y + k) Plot(x + h, -y + k) 4. Compute the location of the next pixel. If d < 0, then d = d + 4x + 6 and x = x + 1. If d > 0, then d = d + 4(x - y) + 10, x = x + 1, and y = y - 1. 5. Go to step 2. Defining an Ellipse using Polynomial Method The ellipse, like the circle, shows symmetry. In the case of an ellipse, however, symmetry is four- rather than eight-way. There are two methods of mathematically defining a ellipse. The polynomial method of defining an ellipse (Fig. 3-9) is given by the expression
where (h, k) = ellipse center
a = length of major axis b = length of minor axis When the polynomial method is used to define an ellipse, the value of x is incremented from h to a. For each step of x, each value of y is found by evaluating the expression
This method is very inefficient, however, because the squares
of a and (x — h) must be found; then floating- point division of (x — h) by a2 and floating-point multiplication of the square root of [1 — (x — h) /a2] by b must be performed Scan Converting an Ellipse using Polynomial Method 1. Set the initial variables: a = length of major axis; b = length of minor axis; (h, k) = coordinates of ellipse center; x = 0; i = step size; xend = a. 2. Test to determine whether the entire ellipse has been scan-converted. If x > xend, stop. 3. Compute the value of the y coordinate: 4. Plot the four points, found by symmetry, at the current (x, y) coordinates: Plot(x + h, y + k) Plot(-x + h, -y + k) Plot(-x + h, y + k) Plot(x + h, -y + k) 5. Increment x: x = x + i. 6. Go to step 2. Defining Ellipse using Trigonometric Method A second method of defining an ellipse makes use of trigonometric relationships. The following equations define an ellipse trigonometrically: x = a cos(ɵ) + h and y = b sin(ɵ) + k where (x, y) = the current coordinates a = length of major axis b = length of minor axis ɵ = current angle (h,k) = ellipse center For generation of an ellipse using the trigonometric method, the value of ɵ is varied from 0 to n/2 radians (rad). The remaining points are found by symmetry. While this method is also inefficient and thus generally too slow for interactive applications, a lookup table containing the values for sin(ɵ) and cos(ɵ) with ɵ ranging from 0 to n/2 rad can be used. Scan Converting an Ellipse using Trigonometric Method 1. Set the initial variables: a = length of major axis; b = length of minor axis; (h, k) = coordinates of ellipse center; i = counter step size; ɵend = n/2; ɵ = 0. 2. Test to determine whether the entire ellipse has been scan-converted. If ɵ > ɵend, stop. 3. Compute the values of the x and y coordinates: x = a cos(ɵ) y = b sin(ɵ) 4. Plot the four points, found by symmetry, at the current (x, y) coordinates: Plot(x + h, y + k) Plot(-x + h, -y + k) Plot(-x + h, y + k) Plot(x + h, -y + k) 5. Increment 8: 8 = 8 + i. 6. Go to step 2