Question:
Write a program to draw any 2-D object and perform the transformations on it according to the input parameters from the user, namely: Translation, Rotation or Scaling
Code:
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void main(){
int g=DETECT,gmode;
initgraph(&g,&gmode,"C://TURBOC3//BGI");
line(200,300,300,200);
int x;
cout<<"Enter Your Choice\nPress 1 For Translation\n2 For Rotation\n3 For Scaling\n";
cin>>x;
if(x==1){
cleardevice();
int tx,ty;
line(200,300,300,200);
cout<<"Enter Translation Along x and y\n";
cout<<"Tx =";
cin>>tx;
cout<<"Ty =";
cin>>ty;
line(200+tx,300+ty,300+tx,200+ty);
}else if(x==2){
cleardevice();
line(200,300,300,200);
cout<<"Enter Rotation Angle:\n";
cout<<"a=";
float a;
cin>>a;
a=a*(3.142/180);
cout<<200*cos(a)-300*sin(a)<<","<<200*sin(a)+300*cos(a)<<","<<300*cos(a)-200*sin(a)<<","<<300*sin(a)+200*cos(a);
//line((int)200*cos(a)-300*sin(a),(int)200*sin(a)+300*cos(a),(int)300*cos(a)-200*sin(a),(int)300*sin(a)+200*cos(a));
line(200*cos(a)-300*sin(a),200*sin(a)+300*cos(a),300*cos(a)-200*sin(a),300*sin(a)+200*cos(a));
}else{
cleardevice();
float sx,sy;
line(200,300,300,200);
cout<<"Enter Scaling along x and y\n";
cout<<"Sx =";
cin>>sx;
cout<<"Sy =";
cin>>sy;
line(200*sx,300*sy,300*sx,200*sy);
}
getch();
}
Output:
Write a program to draw any 2-D object and perform the transformations on it according to the input parameters from the user, namely: Translation, Rotation or Scaling
Code:
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void main(){
int g=DETECT,gmode;
initgraph(&g,&gmode,"C://TURBOC3//BGI");
line(200,300,300,200);
int x;
cout<<"Enter Your Choice\nPress 1 For Translation\n2 For Rotation\n3 For Scaling\n";
cin>>x;
if(x==1){
cleardevice();
int tx,ty;
line(200,300,300,200);
cout<<"Enter Translation Along x and y\n";
cout<<"Tx =";
cin>>tx;
cout<<"Ty =";
cin>>ty;
line(200+tx,300+ty,300+tx,200+ty);
}else if(x==2){
cleardevice();
line(200,300,300,200);
cout<<"Enter Rotation Angle:\n";
cout<<"a=";
float a;
cin>>a;
a=a*(3.142/180);
cout<<200*cos(a)-300*sin(a)<<","<<200*sin(a)+300*cos(a)<<","<<300*cos(a)-200*sin(a)<<","<<300*sin(a)+200*cos(a);
//line((int)200*cos(a)-300*sin(a),(int)200*sin(a)+300*cos(a),(int)300*cos(a)-200*sin(a),(int)300*sin(a)+200*cos(a));
line(200*cos(a)-300*sin(a),200*sin(a)+300*cos(a),300*cos(a)-200*sin(a),300*sin(a)+200*cos(a));
}else{
cleardevice();
float sx,sy;
line(200,300,300,200);
cout<<"Enter Scaling along x and y\n";
cout<<"Sx =";
cin>>sx;
cout<<"Sy =";
cin>>sy;
line(200*sx,300*sy,300*sx,200*sy);
}
getch();
}
Output: