Midpoint Ellipse

Status
Not open for further replies.
I need the source code in C (using Turbo C)to implement the Midpoint Ellipse Drawing Algorithm...

I tried writing it myself, but instead of ellipses, i m getting some wierd shapes...:confused:


Please help if possible...
Thnks in advance..
 

mediator

Technomancer
Ur lucky! I had my practical saved. :twisted:

//Mid Point Ellipse Algorithm

#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
void ellipse_midpoint(int x1,int y1,int rx,int ry)
{
int x,y,p,px,py,rx2,ry2,tworx2,twory2;
rx2=rx*rx;
ry2=ry*ry;
tworx2=2*rx2;
twory2=2*ry2;
x=0;
y=ry;
p=abs(ry2-rx2*ry+(0.25*rx2));
px=0;
py=tworx2*y;
while(px<py)
{
x=x+1;
px=px+twory2;
if(p>=0)
{
y=y-1;
py=py-tworx2;
p=p+ry2+px-py;
}
else
{
p=p+ry2+px;
}
putpixel(x1+x,y1+y,1);
putpixel(x1-x,y1+y,1);
putpixel(x1+x,y1-y,1);
putpixel(x1-x,y1-y,1);
}
p=abs(ry2*(x+0.5)*(x+0.5)+rx2*(y-1)*(y-1)-rx2*ry2);
while(y>0)
{
y=y-1;
py=py-tworx2;
if(p<=0)
{
x=x+1;
px=px+twory2;
p=p+rx2-py+px;
}
else
{
p=p+rx2-py;
}
putpixel(x1+x,y1+y,1);
putpixel(x1-x,y1+y,1);
putpixel(x1+x,y1-y,1);
putpixel(x1-x,y1-y,1);
}
}
void main()
{
int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "c:\\tc\\bgi");
int x1,y1,rx,ry;
cout<<"Enter the centre point of the Ellipse"<<endl;
cin>>x1>>y1;
cout<<"Enter the length of semiMajor & semiMinor axes"<<endl;
cin>>rx>>ry;
ellipse_midpoint(x1,y1,rx,ry);
getch();
}
 
OP
MysticDews
^^
hey thanks a lllottt...
i was really fed up trying all possible PnC in those equations...

will try it out...

Thanks again... :)
 
Status
Not open for further replies.
Top Bottom