EXP4 Ellipse
EXP4 Ellipse
:04
THEORY:
Mid-point Ellipse algorithm is used to draw an ellipse in computer graphics. Midpoint ellipse
algorithm plots(finds) points of an ellipse on the first quadrant by dividing the quadrant
into two regions. Each point(x, y) is then projected into other three quadrants (-x, y), (x, -y), (-x,
-y) i.e. it uses 4-way symmetry
This is an incremental method for scan converting an ellipse that is centered at the origin in
standard position i.e., with the major and minor axis parallel to coordinate system axis. It is very
similar to the midpoint circle algorithm. Because of the four-way symmetry property we need to
consider the entire elliptical curve in the first quadrant.
ALGORITHM:
Step 4: Enter Major and Minor Axis of ellipse as (a=major and b=minor)
p=p+2*b*b*x-2*a*b*b*y+b*b
Step 6:
if(p<0)
x=x+1;
p=p+2*b*b*x+b*b;
else
x=x+1;
y=y-1;
p=p+2*b*b*x-2*a*a*y+b*b;
}
p=(b*b*(x+0.5)*(x+0.5))+((y-1)*(y-1)*a*a-a*a*b*b);
Step 8:
y=y-1;
p=p-2*a*a*y+a*a;
else
x=x+1;
y=y-1;
p=p-2*a*a*y+2*b*b*x+a*a;
Step 9:Closegraph();
Step 10:Stop
PROGRAM:
#include<stdio.h>
#include<graphics.h>
void main()
int gdriver=DETECT,gmode;
float p,x,y,xc,yc,a,b;
initgraph(&gdriver,&gmode,"C:\\turboc3\\bgi");
printf("Enter xc:\n");
scanf("%f",&xc);
printf("Enter yc:\n");
scanf("%f",&yc);
printf("Enter a:\n");
scanf("%f",&a);
printf("Enter b:\n");
scanf("%f",&b);
x=0;
y=b;
//Region 1
p=(b*b)-(a*a*b)+(0.25*a*a);
do
putpixel(xc+x,yc+y,WHITE);
putpixel(xc+x,yc-y,WHITE);
putpixel(xc-x,yc+y,WHITE);
putpixel(xc-x,yc-y,WHITE);
if(p<0)
x=x+1;
p=p+2*b*b*x+b*b;
else
x=x+1;
y=y-1;
p=p+2*b*b*x-2*a*a*y+b*b;
}while(2*b*b*x<2*a*a*y);
//Region 2
p=(b*b*(x+0.5)*(x+0.5))+((y-1)*(y-1)*a*a-a*a*b*b);
do
putpixel(xc+x,yc+y,WHITE);
putpixel(xc+x,yc-y,WHITE);
putpixel(xc-x,yc+y,WHITE);
putpixel(xc-x,yc-y,WHITE);
if(p>0)
y=y-1;
p=p-2*a*a*y+a*a;
else
x=x+1;
y=y-1;
p=p-2*a*a*y+2*b*b*x+a*a;
}while(y!=0);
getch();
closegraph();
}
CONCLUSION: Thus We Midpoint Ellipse Algorithm Implemented Using C