IMPLEMENTATION OF MIDPOINT ELLIPSE ALGORITHM mohanmo V+ Member 05-06-2013, 10:13 PM PROGRAM NAME:IMPLEMENTATION OFMIDPOINT ELLIPSE ALGORITHM PROGRAM LANGUAGE:C 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  /* include the necessary header files*/ #include #include #include #include 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=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); }``` Make a Great History « Next Oldest | « Next Newest