0% found this document useful (0 votes)
9 views5 pages

EXP4 Ellipse

Uploaded by

aafiyahussain9
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views5 pages

EXP4 Ellipse

Uploaded by

aafiyahussain9
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

EXPERIMENT NO.

:04

AIM: Implement midpoint ellipse algorithm using C

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 1: float p,x,y,xc,yc,a,b;

Step 2:int gd=DETECT,gm; initgraph;

Step 3: Enter coordinate of centre of ellipse as (xc,yc)

Step 4: Enter Major and Minor Axis of ellipse as (a=major and b=minor)

Step 5: Calculate Decision parameter for Region 1:

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;
}

Step 7: Calculate Decision parameter for Region 2:

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

You might also like