Resources » Articles/Knowledge Sharing » Computer & Technology

# BRESENHAM’S ELLIPSE DRAWING ALGORITHM

 Updated: 29-Mar-2009 Category: Computer & Technology Author: sasi kala Member Level: Gold Points: 2

#include
#include
#include
void main()
{
long d1,d2;
int i,gd,gm,x,y;
long rx,ry,rxsq,rysq,tworxsq,tworysq,dx,dy;
printf("\n enter the x radius of the ellipse:");
scanf("%ld",&rx);
printf("\n enter the y radius of the ellipse:");
scanf("%ld",&ry);
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"c:\\Tc\\BGI ");
rxsq=rx*rx;
rysq=ry*ry;
tworxsq=2*rxsq;
tworysq=2*rysq;
x=0;
y=ry;
d1=rysq-rxsq*ry+(0.25*rxsq);
dx=tworysq*x;
dy=tworxsq*y;
do
{
putpixel(200+x,200+y,15);
putpixel(200-x,200-y,15);
putpixel(200+x,200-y,15);
putpixel(200-x,200+y,15);
if(d1<0)
{
x=x+1;
y=y;
dx=dx+tworysq;
d1=d1+dx+rysq;
}
else
{
x=x+1;
y=y-1;
dx=dx+tworysq;
dy=dy-tworxsq;
d1=d1+dx-dy+rysq;
}
delay(5);
}
while(dxd2=rysq*(x+0.5)*(x+0.5)+rxsq*(y-1)*(y-1)-rxsq*rysq;
do
{
putpixel(200+x,200+y,15);
putpixel(200-x,200-y,15);
putpixel(200+x,200-y,15);
putpixel(200-x,200+y,15);
if(d2>0)
{
x=x;
y=y-1;
dy=dy-tworxsq;
d2=d2-dy+rxsq;
}
else
{
x=x+1;
y=y-1;
dy=dy-tworxsq;
dx=dx+tworysq;
d2=d2+dx-dy+rxsq;
}}
while(y>0);
getch();
closegraph();
}

Did you like this resource? Share it with your friends and show your love!

Responses to "BRESENHAM’S ELLIPSE DRAWING ALGORITHM"

No responses found. Be the first to respond...

Feedbacks

## Post Comment:

• Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
• No HTML formatting and links to other web sites are allowed.
• This is a strictly moderated site. Absolutely no spam allowed.
•  Name: Sign In to fill automatically. Email: (Will not be published, but required to validate comment) Type the numbers and letters shown on the left.

Complete the action items below to enter to win an iPad Mini from India Study Channel!

### Subscribe to Email

• Get Jobs by Email
• Forum posts by Email
• Articles by Email