Thursday, April 9, 2009

source code

#include
#include
#include
#include
#include
class tdt
{
private:
int n,poly[100],tpoly[100],ypoly[100],tx,ty;
int spoly[100],rpoly[100],sx,sy,rx,ry,ang,h,k;
int shxpoly[100],shx,shy,shypoly[100];
float rad;
public:
void oldpoly();
void transpoly();
void rotatepoly();
void scalepoly();
void shearxpoly();
void shearypoly();
};
void tdt::oldpoly()
{
cout<<"\n Enter the no.of sides";
cin>>n;
cout<<"\n Enter the co-ordinates";
for(int i=0;i<(n*2);i++)
{
cin>>poly[i];
}
poly[i]=poly[0];
poly[i+1]=poly[1];
drawpoly(n+1,poly);
getch();
}
void tdt::transpoly()
{
cout<<"\n Enter thye increment co-ordinates";
cin>>tx>>ty;
for(int i=0;i<(n*2);i++)
{
if(i%2==0)


tpoly[i]=poly[i]+tx;
else
tpoly[i]=poly[i]+ty;
}
tpoly[i]=tpoly[0];
tpoly[i+1]=tpoly[1];
drawpoly(n+1,tpoly);
getch();
}
void tdt::rotatepoly()
{
cout<<"enter the angle";
cin>>ang;
rad=(3.14*ang)/180;
cout<<"enter the point at which rotate";
cin>>h>>k;
for(int i=0;i<(n*2);i=i+2)
{
rpoly[i]=h+(poly[i]-h)*cos(rad)-poly[i+1]*sin(rad);
rpoly[i+1]=k+(poly[i]-h)*sin(rad)+poly[i+1]-k*cos(rad);
}
rpoly[i]=rpoly[0];
rpoly[i+1]=rpoly[1];
drawpoly(n+1,rpoly);
getch();
}
void tdt::shearxpoly()
{
cout<<"\n Enter the point";
cin>>shx;
for(int i=0;i<(n*2);i+=2)
{
shxpoly[i]=poly[i]+(shx*poly[i]);
shxpoly[i+1]=poly[i+1];
}
shxpoly[i]=shxpoly[0];
shxpoly[i+1]=shxpoly[1];
drawpoly(n+1,shxpoly);
getch();
}
void tdt::shearypoly()
{
cout<<"\n Enter the point";
cin>>shy;
for(int i=0;i<(n*2);i+=2)
{
shypoly[i]=poly[i];
shypoly[i+1]=(shy*poly[i+1]+poly[i+1]);
}
shypoly[i]=shypoly[0];
shypoly[i+1]=shypoly[1];
drawpoly(n+1,shypoly);
getch();
}
void tdt::scalepoly()
{
cout<<"\n Enter the scaling distance";
cin>>sx>>sy;
for(int i=0;i<(n*2);i++)
{
if(i%2==0)
{
spoly[i]=poly[i]*sx;
}
else
spoly[i]=poly[i]*sy;
}
spoly[i]=spoly[0];
spoly[i+1]=spoly[1];
drawpoly(n+1,spoly);
getch();
}
void main()
{
int gd=DETECT,gm;
int ch,i;
char op;
initgraph(&gd,&gm,"c:/tc/bgi");
tdt obj;
do
{
cleardevice();
for(i=0;i<7;i++)
{
cout<<"\n menu";
cout<<"\n 1.translate";
cout<<"\n 2.rotate";
cout<<"\n 3.scale";
cout<<"\n 4.shearx";
cout<<"\n 5.sheary";
cout<<"\n 6.exit";
cout<<"\n Enter ur choice";
cin>>ch;
switch(ch)
{
case 1:
obj.oldpoly();
obj.transpoly();
break;
case 2:
obj.oldpoly();
obj.rotatepoly();
break;
case 3:
obj.oldpoly();
obj.scalepoly();
break;
case 4:
obj.oldpoly();
obj.shearxpoly();
break;
case 5:
obj.oldpoly();
obj.shearypoly();
break;
}
cleardevice();
cout<<"\n Do u want to continue";
cin>>op;
}}
while(op!='n');
closegraph();
}




OUTPUT:
2-D-transformation:-

Menu
1. Translate,
2. Scale,
3. Rotate,
4. Shear x,
5. Shear y.
Enter the choice: 1
Enter the no of sides: 6
Enter the co-ordinates 100 100 100 150 150 175 200 150 200 100 150 75
Enter the increment co-ordinate 10 20