Computer Graphics Exp 2
Computer Graphics Exp 2
Lab File
For
UTTAR PRADESH
1|Page
EXP. NO. : 2 DATE: 28/1/2022
PROGRAM :
1. DESCRIPTION (INTRODUCTION)
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
centre.
The algorithm is very similar to the Mid-Point Line Generation Algorithm. Here, only
the boundary condition is different.
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.
2|Page
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 perimeter, we plot the pixel (x, y+1), otherwise
if it’s outside we plot the pixel (x-1, y+1)
Boundary Condition : Whether the mid-point lies inside or outside the circle
can be decided by using the formula:-
Given a circle centered at (0,0) and radius r and a point p(x,y) F(p) =
x2 + y2 – r2
if F(p)<0, the point is inside the circle F(p)=0,
the point is on the perimeter
F(p)>0, the point is outside the circle
2. SOURCE CODE –
#include<stdio.h>
#include<graphics.h>
while (x >= y)
{
putpixel(x0 + x, y0 + y, 7);
putpixel(x0 + y, y0 + x, 7);
putpixel(x0 - y, y0 + x, 7); putpixel(x0
- x, y0 + y, 7); putpixel(x0 - x, y0 - y,
7); putpixel(x0 - y, y0 - x, 7);
putpixel(x0 + y, y0 - x, 7); putpixel(x0
+ x, y0 - y, 7);
3|Page
if (err <= 0) { y
+= 1; err +=
2*y + 1;
}
if (err > 0) { x
-= 1; err -=
2*x + 1;
}
}
}
return 0;
}
3. OUTPUT -
4|Page
5|Page