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 ELLIPSE ALGORITHM
#1


PROGRAM NAME:IMPLEMENTATION OFMIDPOINT ELLIPSE ALGORITHM

PROGRAM LANGUAGE:CHeart

PROGRAM DESCRIPTION:The Midpoint Ellipse Algorithm is a method for drawing ellipses in computer graphics this method is modified from Bresenham’s which starts accordingly with the ellipse equation b2x2 + a2y2 – a2b2 = 0 where a is the horizontal radius and b is the vertical radius


Code:
#include<stdio.h>  /* include the necessary header files*/
#include<conio.h>
#include<graphics.h>
#include<math.h>
#include<stdlib.h>
void plotpoints(int,int,int,int);
void main()
{
int gd=DETECT,gm;
int xcenter,ycenter,rx,ry;
int p,x,y,px,py,rx1,ry1,rx2,ry2;
initgraph(&gd,&gm,"C:\\TC\\BGI");  /* request auto detect*/
printf("\n Enter the radius :");  /* get the radius and the center values*/
scanf("%d %d",&rx,&ry);
printf("\n Enter the xcenter and ycenter values :");
scanf("%d %d",&xcenter,&ycenter);
ry1=ry*ry;
rx1=rx*rx;
ry2=2*ry1;
rx2=2*rx1;
/* Region 1 */
x=0;
y=ry;
plotpoints(xcenter,ycenter,x,y);  /* for the first region calculate the condition parameter*/
p=(ry1-rx1*ry+(0.25*rx1));
px=0;
py=rx2*y;
printf("\nx\ty\tp\tpx\tpy\n");
printf("\n%d\t%d\t%d\t%d\t%d",x,y,p,px,py);
while(px<py)  /* if this condition is true, compute values of x and y*/
{
x=x+1;
px=px+ry2;
if(p>=0)
{
y=y-1;
py=py-rx2;
p=p+ry1+px-py;
  }
  else
  p=p+ry1+px;
  plotpoints(xcenter,ycenter,x,y);  /* call the plotpoints function*/
  printf("\n%d\t%d\t%d\t%d\t%d",x,y,p,px,py);
}
/* Region 2 */ 
printf("\n%d\t%d\t%d\t%d\t%d",x,y,p,px,py);
printf("\n\nRegion 2\n");
printf("\nx\ty\tp\tpx\tpy\n");  /* for region 2 recalculate the condition variables*/
p=(ry1*(x+0.5)*(x+0.5)+rx1*(y-1)*(y-1)-rx1*ry1);
while(y>0)
{
y=y-1;
py=py-rx2;
if(p<=0)
{
x=x+1;
px=px+ry2;
}
if(p>0)
p=p+rx1-py;
else
p=p+rx1-py+px;
plotpoints(xcenter,ycenter,x,y);  /* draw the pixels for region 2*/
printf("\n%d\t%d\t%d\t%d\t%d",x,y,p,px,py);

}

getch();
closegraph();
}
void plotpoints(int xcenter,int ycenter,int x,int y) /* plot the points of the circle as per the procedure*/
{
putpixel(xcenter+x,ycenter+y,6);
putpixel(xcenter-x,ycenter+y,6);
putpixel(xcenter+x,ycenter-y,6);
putpixel(xcenter-x,ycenter-y,6);
}


Heart
Make a Great History


Reply

Subscribe


Recommend on Google