Ellipse
Ellipse
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void draw(int x,int y);
void main()
{
int gdriver=DETECT,gmode;
int max,min,x,y;
long s1,s2,p,q;
initgraph(&gdriver,&gmode,"C:\\TC\\BGI\\");
printf("\n\nEnter the major axis :");
scanf("%d",&max);
printf("\nEnter the minor axis :");
scanf("%d",&min);
x=0;
y=min;
s1=pow(min,2);
s2=pow(max,2);
p=(s1-(s2*min)+(.25*s2));
draw(x,y);
while(s2*(y-0.5)>s1*(x+1))
{
x++;
if(p<0)
p=(p+s1*(2*x+3));
else
{
p=(p+s1*(2*x+3)+s2*(-2*y+2));
y--;
}
draw(x,y);
}
q=s1*pow((x+0.5),2)+s2*pow((y-1),2)-s1*s2;
while(y>0)
{
if(q<0)
{
q=q+s1*(2*x+2)+s2*(-2*y+3);
x++;
}
else
q=q+s2*(-2*y+3);
y--;
draw(x,y);
}
getch();
closegraph();
}
void draw(int x,int y)
{
putpixel(x+200,y+200,7);
putpixel(-x+200,y+200,7);
putpixel(x+200,-y+200,7);
putpixel(-x+200,-y+200,7);
}
OUTPUT:
Enter the Major Axis :100
Enter the Minor Axis :50