# 2-D Transformations for an Object (C++)

Problem Definition: Write a program to implement 2-D Transformations viz., (a) Translation (b) Rotation (c) Scaling for an Object.

#include <conio.h>
#include <iostream.h>
#include <graphics.h>
#include <math.h>
void main(){
int x1=200,y1=200,x2=250,y2=250,x3=180,y3=270,option;
int gdriver = DETECT,gmode;
initgraph(&gdriver,&gmode,”C:\TC\BGI”);
do{
cleardevice();
gotoxy(1,1);
line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
line(x3,y3,x1,y1);
cout<<“\n1.Translation 2.Scaling 3.Rotation 4.Exit\nEnter your choice: “;
cin>>option;
switch(option){
case 1:
float tx,ty;
cout<<“Enter tx & ty: “;
cin>>tx>>ty;
x1+=tx;x2+=tx;x3+=tx;
y1+=ty;y2+=ty;y3+=ty;
break;

case 2:
float sx,sy;
cout<<“Enter sx & sy: “;
cin>>sx>>sy;
x1*=sx;x2*=sx;x3*=sx;
y1*=sy;y2*=sy;y3*=sy;
break;

case 3:
float deg;
cout<<“Enter angle: “;
cin>>deg;
deg = deg*3.14/180;
int x,y;
x=x1;y=y1;
x1 = x*cos(deg)-y*sin(deg);
y1 = x*sin(deg)+y*cos(deg);
x=x2;y=y2;
x2 = x*cos(deg)-y*sin(deg);
y2 = x*sin(deg)+y*cos(deg);
x=x3;y=y3;
x3 = x*cos(deg)-y*sin(deg);
y3 = x*sin(deg)+y*cos(deg);
break;

case 4:
break;

default:
cout<<“Invalid choice”;
}
}while(option!=4);
closegraph();
}

## 6 thoughts on “2-D Transformations for an Object (C++)”

1. Aniket says:

Where is the output

1. Hey Aniket, I haven’t included the o/p in this program itself. But, you would be able to generate it after running it.

2. nitheesh says:

i cant geting output
in windows8

1. Hey Nitheesh, what error did it throw? OS shouldn’t matter, did you run it in Turbo C?

3. Fantastic work done in this program I salute you guys.