Name - Rakesh Choudhary Sap-ID-500071544 Enrollment-no-R172218167 CSE-Big Data Batch-B3

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Name –Rakesh Choudhary

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>

void plotpixel(int xc,int yc,int x,int y)


{
putpixel(x+xc,y+yc,WHITE);
putpixel(x+xc,-y+yc,WHITE);
putpixel(-x+xc,-y+yc,WHITE);
putpixel(-x+xc,y+yc,WHITE);
putpixel(y+xc,x+yc,WHITE);
putpixel(y+xc,-x+yc,WHITE);
putpixel(-y+xc,-x+yc,WHITE);
putpixel(-y+xc,x+yc,WHITE);
}

void bresenhamCircle(int xc,int yc,int r)


{
int x=0;
int y=r;
float 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);
}
}
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:-

You might also like