Tuesday, April 13, 2010

Midpoint Ellipse

#include
#include
#include
#include
int xc,yc;
void plotpoints(int,int,int,int);
void plotpoints(int xc,int yc,int x,int y)
{
putpixel(xc+x,yc+y,1);
putpixel(xc-x,yc+y,1);
putpixel(xc+x,yc-y,1);
putpixel(xc-x,yc-y,1);
}
void main()
{
int p,px,x,y,rx2,ry2,a,b,py,tworx2,twory2,py2,k;
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\TC\\BGI");
clrscr();
printf("Enter the centre co-ordinates: ");
scanf("%d%d",&xc,&yc);
printf("Enter the midpoint: ");
scanf("%d%d",&a,&b);
ry2=b*b;
rx2=a*a;
tworx2=2*rx2;
twory2=2*ry2;
x=0;
y=b;
plotpoints(xc,yc,k,y);
p=ceil(ry2-rx2*b+(0.25*rx2));
px=0;
py=tworx2*y;
while(px
{
x=x+1;
px=px+twory2;
if(p>=0)
{
y=y-1;
py=py-tworx2;
}
if(p<0)
{
p=p+ry2+px;
}
else
{
p=p+ry2+px-py;
}
plotpoints(xc,yc,x,y);
}
p=ceil(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;
}
if(p>0)
{
p=p+rx2-py;
}
else
{
p=p+rx2-py+px;
}
plotpoints(xc,yc,x,y);
}
getch();
}

0 comments:

Post a Comment

 
ShareThis

Visitor

Website counter
Copyright 2009 Code's. Powered by Blogger
Blogger Templates created by Deluxe Templates
Wordpress by Wpthemescreator
Blogger Showcase