A C++ program to draw a ellipse using polar co-ordinates.


# include <iostream.h>
# include <graphics.h>
# include<conio.h>
# include <math.h>
void trigonometric_ellipse(const int,const int,const int,const int);
int main( ){
int gd=DETECT;
int gm;
int h=0;
int k=0;
int rx=0;
int ry=0;
cout<<“Enter the co-ordinate of X = “;
cin>>h;
cout<<“Enter the co-ordinate of Y = “;
cin>>k;
cout<<“Radius of the Ellipse : (rx,ry) :”<<endl;
cout<<“————————————–“<<endl;
cout<<“Enter the radius along x-axis : rx = “;
cin>>rx;
cout<<“Enter the radius along y-axis : ry = “;
cin>>ry;
initgraph(&gd,&gm,””);
setcolor(15);
trigonometric_ellipse(h,k,rx,ry);
getch();
closegraph();
return 0;}
void trigonometric_ellipse(const int h,const int k,const int rx,const int ry){
int color=getcolor( );
float x=0;
float y=ry;
float angle=0;
float range=rx;
do{
putpixel((int)(h+x+0.5),(int)(k+y+0.5),color);
putpixel((int)(h+x+0.5),(int)(k-y+0.5),color);
putpixel((int)(h-x+0.5),(int)(k-y+0.5),color);
putpixel((int)(h-x+0.5),(int)(k+y+0.5),color);
angle+=0.05;
x=(rx*cos(angle));
y=(ry*sin(angle));}
while(angle<=range);
}