# Mid-Point Ellipse Generation Algorithm (C++)

Problem Definition: Write a program to implement Mid-Point Ellipse Generation Algorithm.

#include <graphics.h>
#include <iostream.h>
#include <conio.h>
void main(){
int xc,yc,x,y,d,r;
int gdriver = DETECT, gmode;
initgraph(&gdriver,&gmode,”C:\TC\BGI”);
cout<<“Enter co-ordinates of centre: “;
cin>>xc>>yc;
cout<<“Enter radius of circle: “;
cin>>r;
x = 0;
y = r;
d = 3-2*r;
do{
if(d<0){
d += 4*x +6;
x++;
}
else{
d += 4*x – 4*y +10;
x++;
y–;
}
putpixel(xc+x,yc+y,WHITE);
putpixel(xc+y,yc+x,WHITE);
putpixel(xc+x,yc-y,WHITE);
putpixel(xc+y,yc-x,WHITE);
putpixel(xc-x,yc-y,WHITE);
putpixel(xc-y,yc-x,WHITE);
putpixel(xc-x,yc+y,WHITE);
putpixel(xc-y,yc+x,WHITE);
}
while(x<y);
getch();
closegraph();
}

## 4 thoughts on “Mid-Point Ellipse Generation Algorithm (C++)”

1. Raj says:

i think the heading is given for ellipse and circle has been drawn :p

1. A circle is an ellipse after all 😉
You’ll find a circle drawing algo in another post, believe me, this one’s called “Mid-Point Ellipse” algo.

This site uses Akismet to reduce spam. Learn how your comment data is processed.