Headlines
Loading...
Computer graphics program - Midpont ellipse algorithm

Computer graphics program - Midpont ellipse algorithm

Midpont ellipse algorithm.
Code
#include<dos.h>
#include<math.h>
#include<graphics.h>
#include<conio.h>
#define ROUND(a) ((int)(a+0.5))
void ellipseMidPoint(long,long,long,long);
void main()
{
 float p;
 int gd=DETECT,gm,x,y;
 int r,i;
 long xcent,ycent,min,maj;
 initgraph(&gd,&gm,"c:\\tc\\bgi");
 printf("MIDPOINT ELLIPSE DRAWING ALGORITHM\n");
printf("Enter the x value of center co-ordinates:");
 scanf("%ld",&xcent);
 printf("Enter the y value of center co-ordinates:");
 scanf("%ld",&ycent);
 printf("Enter the major radius         :");
 scanf("%ld",&maj);
 printf("Enter the minor radius         :");
 scanf("%ld",&min);
 cleardevice();
 ellipseMidPoint(xcent,ycent,maj,min);
 getch();
 closegraph();
 restorecrtmode();
}
void ellipseMidPoint ( long xC, long yC, long Rx, long Ry)
{
long Rx2 = Rx*Rx;
long Ry2 = Ry*Ry;
long twoRx2=2*Rx2;
long twoRy2=2*Ry2;
long p;
long x=0;
long y=Ry;
long px=0;
long py=twoRx2*y;

void ellipsePlotPoints (long,long,long,long);

ellipsePlotPoints (xC,yC,x,y) ;

//Region 1
p=ROUND(Ry2-(Rx2*Ry)+(0.25 *Rx2));
while(px<py)
{
x++;
px+=twoRy2;
if(p<0)
p += Ry2 + px;
else
{
y--;
py-=twoRx2;
p+=Ry2+px-py;
}
ellipsePlotPoints(xC,yC,x,y);
}
p = ROUND(Ry2*(x)*(x)+ Rx2*(y-1)*(y-1)-Rx2*Ry2);
while (y > 0 )
{
y--;
py-=twoRx2;
if(p>0)
p+=Rx2-py;
else {
x++;
px+=twoRy2;
p+= Rx2 - py + px;
}
ellipsePlotPoints(xC,yC,x,y);
}
}
void ellipsePlotPoints(long xC,long yC,long x,long y)
{
long i;
putpixel(xC+x,yC + y,15);
putpixel(xC-x,yC + y,15);
putpixel(xC+x,yC - y,15);
putpixel(xC-x,yC - y,15);
}

*** PLEASE checkout the Best deals from for top sites like Amazon, Flipkart etc ***