SUBJECT COMPUTER GRAPHICS Topic Circle Generating Algorithm It

SUBJECT: COMPUTER GRAPHICS Topic: Circle Generating Algorithm

� � It is not easy to display a continuous smooth arc on the computer screen as our computer screen is made of pixels organized in matrix form. So, to draw a circle on a computer screen we should always choose the nearest pixels from a printed pixel so as they could form an arc. There are two algorithm to do this: Mid-Point Circle Drawing Algorithm Bresenham's Algorithm

Mid-Point Circle Drawing Algorithm � � � The mid-point circle drawing algorithm is an algorithm used to determine the points needed for rasterizing a circle. We use the mid-point algorithm to calculate all the perimeter points of the circle in the first octant and then print them along with their mirror points in the other octants. This will work because a circle is symmetric about it’s center.

Mid-Point Circle Drawing Algorithm

Mid-Point Circle Drawing Algorithm � � � For any given pixel (x, y), the next pixel to be plotted is either (x, y+1) or (x-1, y+1). This can be decided by following the steps below. 1: Find the mid-point p of the two possible pixels i. e (x-0. 5, y+1) 2: If p lies inside or on the circle parameter, we plot the pixel (x, y+1), otherwise if it’s outside we plot the pixel (x-1, y+1)

Mid-Point Circle Drawing Algorithm � � � void mid. Point. Circle. Draw(int x_centre, int y_centre, int r) { int x = r, y = 0; printf("(%d, %d) ", x + x_centre, y + y_centre); if (r > 0) { printf("(%d, %d) ", x + x_centre, -y + y_centre); printf("(%d, %d) ", y + x_centre, x + y_centre); printf("(%d, %d)n", -y + x_centre, x + y_centre); }

Mid-Point Circle Drawing Algorithm � � � � int P = 1 - r; while (x > y) { y++; if (P <= 0) P = P + 2*y + 1; else { x--; P = P + 2*y - 2*x + 1; } if (x < y) break;

Mid-Point Circle Drawing Algorithm � � � � printf("(%d, %d) ", x + x_centre, y + y_centre); printf("(%d, %d) ", -x + x_centre, y + y_centre); printf("(%d, %d) ", x + x_centre, -y + y_centre); printf("(%d, %d)n", -x + x_centre, -y +y_centre); if (x != y) { printf("(%d, %d) ", y + x_centre, x + y_centre); printf("(%d, %d) ", -y + x_centre, x + y_centre); printf("(%d, %d) ", y + x_centre, -x + y_centre); printf("(%d, %d)n", -y + x_centre, -x + y_centre); } }} Int main() { Mid. Point. Circle. Draw(0, 0, 3); Return 0; }

- Slides: 9