## Midpoint Ellipse theorem

This is an incremental method of scan converting an ellipse that is centered at the origin in standard position depends upon h & k. It works in a way that is by similar midpoint circle algorithm, because of the four ways symmetric property we need to consider the entire need to curve in the first coordinate.

Suppose we have a function f that can be use to decide if the midpoint between two candidate pixels is inside or outside the ellipse. Function of (x,y)

f(x,y) = b^2 x^2+a^2 y^2 - a^2 b^2

if < 0 it means (x,y) inside the ellipse
If = 0 (x,y) on the ellipse
If > 0 (x,y) outside the ellipse

Suppose that the coordinates of the last scan converted pixel upon standing. (xi, yi) then we are selected the next point as (xi+1, yi) or (xi+1, yi+1) the midpoint of the vertical line connecting outer and inside is used to define the following decision parameter.

#include<stdio.h>

#include<conio.h>

void main()

{

Int xc, yc, rx, ry;

printf(“Enter the value of xc & yc”);

scanf(“%d %d”, &xc, &yc);

printf(“Enter the value of rx & ry”);

scanf(“%d %d”, &rx, &ry);

ellipse(xc, yc, rx, ry);

getch();

}

void ellipse(int xc, int yc, int rx, int ry)

{

int gm=DETECT, gd;

int x, y, p;

initgraph(&gm, &gh,”c://TC//BGI”);

x=0;

y=ry;

p=(xy*ry)-(rx*rx*ry)+((rx*rx)/4);

while((2*x*ry*ry)<(2*y*rx*ry))

{

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*ry*ry*x)+(ry*ry);

}

else

{

x=x+1;

y=y-1;

p=p+(2*ry*ry*x+ry*ry)-(2*rx*rx*y);

}

p=((float)x+0.5)*((float)x+0.5)*ry*ry+(y-1)*(y-1)*rx*rx-rx*rx*ry*ry;

while(y>=0)

{

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*rx*rx*y)+(rx*rx);

}

else

{

y=y-1;

x=x+1;

p=p+(2*ry*ry*rx)-(2*rx*rx*y)-(rx*rx);

}

}

}

}