Академический Документы
Профессиональный Документы
Культура Документы
x2 + y2 = r 2
where r is the radius of the circle So, we can write a simple circle drawing algorithm by solving the equation for y at unit x intervals using:
y= r x
2
Figure 6-11 Circle with center coordinates (xc , yc) and radius r .
Figure 6-12 Upper half of a circle plotted with Equation 6-27 and with (xc , yc) = (0, 0).
Eight-Way Symmetry
(-x, y)
(y,x)
(-x,y)
R 2
(x,y)
(x, -y)
(y, -x)
(xk+1, yk-1)
f circ ( x, y ) = x 2 + y 2 r 2
The equation evaluates as follows:
< 0, if ( x, y ) is inside the circle boundary f circ ( x, y ) = 0, if ( x, y ) is on the circle boundary > 0, if ( x, y ) is outside the circle boundary
By evaluating this function at the midpoint between the candidate pixels we can make our decision
pk = f circ ( xk + 1, yk 1 ) 2 = ( xk + 1) 2 + ( yk 1 ) 2 r 2 2
If pk < 0 the midpoint is inside the circle and the pixel at yk is closer to the circle Otherwise the midpoint is outside and yk-1 is closer
2 2 pk +1 = pk + 2( xk + 1) + ( yk +1 yk ) ( yk +1 yk ) + 1
pk +1 = pk + 2 xk +1 + 1
If pk > 0 then the decision variable is:
pk +1 = pk + 2 xk +1 + 1 2 yk + 1
( x0 , y0 ) = (0, r )
Calculate the initial value of the decision parameter as: p0 = 5 r 4 Starting with k = 0 at each position xk, perform the following test. If pk < 0, the next point along the circle centred on (0, 0) is (xk+1, yk) and:
pk +1 = pk + 2 xk +1 + 1
pk +1 = pk + 2 xk +1 + 1 2 yk +1
4. 5.
Determine symmetry points in the other seven octants Move each calculated pixel position (x, y) onto the circular path centred at (xc, yc) to plot the coordinate values:
x = x + xc
y = y + yc
6.