Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as Plain Text by 2d ( 14 years ago )
Aim:To implement 2D Transformations
PROGRAM:
# include<iostream.h>
# include<conio.h>
# include<math.h>
# include<DOS.h>
# include<graphics.h>
void main()
{
clrscr();
float x1,y1,x2,y2,x3,y3;
int gd=DETECT,gm;
int c;
float tt,sf,rf;
initgraph(&gd;,&gm;,"");
/*line(92,100,42,200);
line(42,200,142,200);
line(142,200,92,100);
delay(5);*/
cout<<"select case: 1. Translation 2. Scaling 3. Rotation";
cin>>c;
switch(c)
{
case 1: cout<<"Enter translation factor:";
cin>>tt;
cout<<"original figure:" ;
line(92,100,42,200);
line(42,200,142,200);
line(142,200,92,100);
cout<<"\t translated figure: ";
x1=92+tt;
y1=100+tt;
x2=42+tt;
y2=200+tt;
x3=142+tt;
y3=200+tt;
cout<<"\t\t\t\t\t\t";
line(x1,y1,x2,y2);
cout<<"\t\t\t\t\t\t";
line(x2,y2,x3,y3);
cout<<"\t\t\t\t\t\t";
line(x3,y3,x1,y1);
break;
case 2: cout<<"Enter scaling factor:\n ";
cin>>sf;
cout<<"original figure:\n" ;
line(92,100,42,200);
line(42,200,142,200);
line(142,200,92,100);
cout<<"\t scaled figure:\t\t ";
x1=92*sf;
y1=100*sf;
x2=42*sf;
y2=200*sf;
x3=142*sf;
y3=200*sf;
line(x1,y1,x2,y2);
cout<<"\t\t\t\t";
line(x2,y2,x3,y3);
cout<<"\t\t\t\t";
line(x3,y3,x1,y1);
break;
case 3: cout<<"Enter theta value:\n ";
cin>>rf;
cout<<"original figure:\n" ;
line(92,100,42,200);
line(42,200,142,200);
line(142,200,92,100);
cout<<" \t\t\t\t rotated figure:\t\t ";
x1=(92*cos(rf)-100*sin(rf));
y1=(92*sin(rf)+100*cos(rf));
x2=(42*cos(rf)-200*sin(rf));
y2=(42*sin(rf)+200*cos(rf));
x3=(142*cos(rf)-200*sin(rf));
y3=(142*sin(rf)+200*cos(rf));
cout<<"\t \t \t \t\t \t \t \t";
line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
line(x3,y3,x1,y1);
break;
case 4: cout<<"Invalid!!!" ;
break;
}
getch();
closegraph();
}
Revise this Paste