Hello There, Guest! RegisterLogin with Facebook
Login with Facebook

New Anna University Nov / Dec 2016 Examination Important Questions
New Anna University (UG / PG) Nov/Dec 2016 and Jan 2017 Theory , Practical Exam Timetable
>>> Anna University Sixth Semester Question Bank Collection (R2013) ECE,MECH,CSE,IT,EEE,CIVIL,EIE
>>> Anna University November/December 2015 Examination Question Papers
>>> Anna University Study Materials for all Departments
>>> Anna University Question Papers : April May June 2015 Question Papers | Nov Dec 2014 and Jan 2015 Question Papers

Register or Login to Submit Study Materials , Shoutbox and also to access Many Features !!

Vidyarthiplus Shop :: Handwritten Premium Lecture Notes
Share your Study Materials with us
Share your Study Materials with us : Click Here

IMPLEMENTATION OF MIDPOINT CIRCLE ALGORITHM
#1
Thumbs Up 


PROGRAM NAME:IMPLEMENTATION OFMIDPOINT CIRCLE ALGORITHM



PROGRAM LANGUAGE:C

PROGRAM SOFTWARE:C Complier

PROGRAM DESCRIPTION:The MidPoint Circle Algorithm is an algorithm used to determine the points needed for drawing a circle. The algorithm is a variant of Bresenham's line algorithm, and is thus sometimes known as Bresenham's circle algorithm. Which starts accordingly with the circle equation x2 + y2 = r2. And with the center of the circle is located at (0, 0)


Code:
#include<stdio.h>   /* include the necessary header files*/
#include<conio.h>
#include<math.h>
#include<graphics.h>
main()
{
int gd=DETECT,gin;
int xcenter,ycenter,radius;
int p,x,y,twox,twoy;   /*request auto detect*/
initgraph(&gd,&gin,"C:\\tc\\bgi");
x=0;
printf("\nEnter the radius value:");  /* get the value of the radius and center values*/
scanf("%d",&radius);
printf("Enter the center values:");
scanf("%d %d",&xcenter,&ycenter);
plotpoints(xcenter,ycenter,x,y); /* call the plotpoints function*/
y=radius;
p=1-radius;
twox=2*x;
twoy=2*y;
printf("\np\tx\ty\t2x\t2y\n");
printf("\n%d\t%d\t%d\t%d\t%d\n",p,x,y,twox,twoy);
while(x<y) /* in the conditional loop compute the value of the x and y values*/
{
if(p<0)
x=x+1;
else
{
x=x+1;
y=y-1;
}
if(p<0)
p=p+2*x+1;
else
p=p+2*(x-y)+1;
twox=2*x;
twoy=2*y;
printf("\n%d\t%d\t%d\t%d\t%d\n",p,x,y,twox,twoy);
plotpoints(xcenter,ycenter,x,y);
}
getch();
return 0;
}
int plotpoints(int xcenter, int ycenter,int x,int y) /* plot the points of the circle as per the procedure*/
{
putpixel(xcenter+x,ycenter+y,1);
putpixel(xcenter-x,ycenter+y,1);
putpixel(xcenter+x,ycenter-y,1);
putpixel(xcenter-x,ycenter-y,1);
putpixel(xcenter+y,ycenter+x,1);
putpixel(xcenter-y,ycenter+x,1);
putpixel(xcenter+y,ycenter-x,1);
putpixel(xcenter-y,ycenter-x,1);
}


Heart
Make a Great History


Reply

Subscribe


Recommend on Google