Friday, May 14, 2010

Ellipse Drawing Algorithm in C++ Program Using Midpoint CS1355-Graphics and Multimedia Lab

Ellipse drawing algorithm is drawn by there plot ellipse function in these program.
Plot ellipse function all the variable is passed by the float variable. And the final a1 data variable is find and declare by the long data variable .I also use the other method to draw the ellipse drawing using mid point algorithm see that program and source code ellipse drawing algorithm.There header files are iostream.h conio.h graphics.h math.h stdlib.h stdio.h
Source code in c++ Language Programming For ellipse drawing algorithm
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
#include<stdlib.h>
#include<stdio.h>
void plotellipse(float,float,float,float);
class ellip
{
private:
float a,b,xc,yc,x,y,h,v,k;
public:
void getdata();
void plot();
};
void ellip::getdata()
{
cout<<"Enter the value for a and b:";
cin>>a>>b;
}
void ellip::plot()
{
xc=getmaxx()/2;
yc=getmaxy()/2;
line(0,yc,xc*2,yc);
line(xc,0,xc,yc*2);
for(k=0;k<360;k++)
{
h=a*cos((k*3.14)/180);
v=b*sin((k*3.14)/180);
x=h;
y=v;
plotellipse(xc,yc,x,y);
}
}
void main()
{
ellip p;
int gd=DETECT,gm;
initgraph(&gd,&gm,"C:/tc/bgi");
cleardevice();
gotoxy(2,2);
p.getdata();
settextstyle(2,0,8);
outtextxy(325,5,"ELLIPSE");
p.plot();
getch();
closegraph();
}
void plotellipse(float xc,float yc,float x,float y)
{
int i,j;
long a1,a2;
getaspectratio(&i,&j);
a1=(long)x*(long)j/(long)i;
a2=(a1);
putpixel(xc+a2,yc+y,15);
putpixel(xc-a2,yc+y,15);
putpixel(xc+a2,yc-y,15);
putpixel(xc-a2,yc-y,15);
}
Output of Ellipse Drawing Algorithm CS1355-Graphics and Multimedia Lab
Ellipse Drawing Algorithm in C++ Program Using Midpoint CS1355-Graphics and Multimedia Lab

0 comments:

Flag counter

free counters