Name - Rakesh Choudhary Sap-ID-500071544 Enrollment-no-R172218167 CSE-Big Data Batch-B3
Name - Rakesh Choudhary Sap-ID-500071544 Enrollment-no-R172218167 CSE-Big Data Batch-B3
Name - Rakesh Choudhary Sap-ID-500071544 Enrollment-no-R172218167 CSE-Big Data Batch-B3
Sap-ID-500071544
Enrollment-no-R172218167
CSE-Big Data
Batch-B3
Computer Graphics
Experiment-9
Title: To implement Mid Point Circle drawing algorithm.
Theory:-
This algorithm is needed for rasterizing a circle.
It plot the points of one octant.
After plotting the points of first octant, it prints the mirror points in
other octants.
In every iteration we have to choose between two points i.e. (x+1 ,y1)
or (x+1 ,y-1).
Algorithm:-
bresenhamCircle(int xc,int yc,int r)
{
x=0,y=r;
d=(5/4)-r;
plotpixel(xc,yc,x,y);
while(x<=y)
{
if(d<=0)
{
d=d+(2*x)+3;
}
else
{
d=d+(2*x)-(2*y)+5;
y--;
}
x++;
plotpixel(xc,yc,x,y);
}
}
Code:-
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <math.h>
while(x<=y)
{
if(d<=0)
{
d=d+(2*x)+3;
}
else
{
d=d+(2*x)-(2*y)+5;
y--;
}
x++;
plotpixel(xc,yc,x,y);
}
}
int main(void)
{
int xc,yc,r,gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "C:\\TURBOC3\\BGI");
bresenhamCircle(250,250,200);
getch();
return 0;
}
Output:-