Circle Drawing Algorithms Circle Drawing Algos Breshenhams Circle
Circle Drawing Algorithms
Circle Drawing Algos • Breshenham’s Circle Drawing Algo • Mid-point Circle Drawing Algo
Scan Conversion of Circles • Assumptions: – circle at (0, 0) – Fill 1/8 of the circle, then use symmetry Not using the 8 -way symmetry of a circle Using the 8 -way symmetry of a circle:
Eight-way Symmetry
Scan Conversion of Circles • Implicit representation of the circle function: • Note: < 0 for points inside the circle, and > 0 for points outside the circle 5
Scan Conversion of Circles • • • Assume we finished pixel What pixel to draw next? (going clockwise) Note: the slope of the circular arc is between 0 and – 1 – Hence, choice is between: E and SE • Idea: If the circle passes above the midpoint M, then we go to E next, otherwise we go to SE 6 1994 Foley/Van. Dam/Finer/Huges/Phillips ICG
Bresenham’s Circle Algo • We cannot display a continuous arc on the raster display. Instead, we have to choose the nearest pixel position to complete the arc. • From the following illustration, you can see that we have put the pixel at (X, Y) location and now need to decide where to put the next pixel − at N (X+1, Y) or at S (X+1, Y-1).
This can be decided by the decision parameter d. • If d <= 0, then N(X+1, Y) is to be chosen as next pixel. • If d > 0, then S(X+1, Y-1) is to be chosen as the next pixel.
Bresenham’s Circle Algo int x=0, y=r, d=3 -2 r; while(x<=y) { putpixel(x, y, color); if(d<0) d=d+4 x+6; else { d=d+4(x-y)+10; y--; } x++; }
Mid-Point Circle Algorithm • Assume that we just plotted point (xk, yk) • The next point is a choice between (xk+1, yk) and (xk+1, yk-1) • We would like to choose the point that is nearest to the actual circle • So how do we make this choice? (xk+1, yk) (xk+1, yk-1)
Mid-Point Circle Algorithm 6 5 4 3 1 2 3 4
Mid-Point Circle Algorithm 6 M 5 4 3 1 2 3 4
Mid-Point Circle Algorithm 6 M 5 4 3 1 2 3 4
Mid-Point Circle Algorithm • Let’s the equation of the circle slightly to give us: • The equation evaluates as follows: • By evaluating this function at the midpoint between the candidate pixels we can make our decision
Mid-Point Circle Algorithm • Assuming we have just plotted the pixel at (xp, yp) so we need to choose between (xp+1, yp) and (xp+1, yp-1) • Our decision variable can be defined as: • If dk < 0 the midpoint is inside the circle and the pixel at yp is closer to the circle • Otherwise the midpoint is outside and yp-1 is closer
Mid-Point Circle Algorithm • To ensure things are as efficient as possible we can do all of our calculations incrementally • First consider: • or: • where yp+1 is either yp or yp-1 depending on the sign of dk
Midpoint Circle Algo int x=0, y=r, d=1 -r; while(x<=y) { putpixel(x, y, color); if(d<0) d=d+2 x+3; else { d=d+2(x-y)+5; y--; } x++; }
- Slides: 17