#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<graphics.h>
#include<math.h>
#include<dos.h>
void main()
{
clrscr();
int gdriver = DETECT, gmode;
int x1,x2,y1,y2,steps;
cout<<"Enter the first point\n";
cin>>x1;
cin>>y1;
cout<<"Enter the last point\n";
cin>>x2;
cin>>y2;
int a1[3][1]={x1,y1,1};
int a2[3][1]={x1,y2,1};
int a3[3][1]={x2,y2,1};
int a4[3][1]={x2,y1,1};
initgraph(&gdriver, &gmode, "Z:\TC\BGI");
line(x1,y1,x1,y2);
line(x1,y2,x2,y2);
line(x2,y2,x2,y1);
line(x2,y1,x1,y1);
cout<<"1> Translation\n";
cout<<"2> Rotation\n";
cout<<"3> Scale\n";
int c;
cin>>c;
double c1[3][1];
double c2[3][1];
double c3[3][1];
double c4[3][1];
switch(c)
{
case 1:int x,y;
cout<<"Enter x displacement\n";
cin>>x;
cout<<"Enter y displacement\n";
cin>>y;
int d[3][3]={1,0,x,0,1,y,0,0,1};
for(int i=0;i<3;i++)
{
c1[i][0]=0;
c2[i][0]=0;
c3[i][0]=0;
c4[i][0]=0;
}
for(i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
c1[i][0]+=d[i][j]*a1[j][0];
c2[i][0]+=d[i][j]*a2[j][0];
c3[i][0]+=d[i][j]*a3[j][0];
c4[i][0]+=d[i][j]*a4[j][0];
}
}
clrscr();
initgraph(&gdriver, &gmode, "Z:\TC\BGI");
line(c1[0][0],c1[1][0],c2[0][0],c2[1][0]);
line(c2[0][0],c2[1][0],c3[0][0],c3[1][0]);
line(c3[0][0],c3[1][0],c4[0][0],c4[1][0]);
line(c4[0][0],c4[1][0],c1[0][0],c1[1][0]);
break;
case 2:double u,v,o;
cout<<"Enter angle\n";
cin>>o;
u=cos(o);
v=sin(o);
int l,m;
l=a1[0][0]*(1-u)+a2[1][0]*v;
m=a1 [1][0]*(1-u)-a2[0][0]*v;
double b[3][3]={u,(-1*v),l,v,u,m,0,0,1};
for( i=0;i<3;i++)
{
c1[i][0]=0;
c2[i][0]=0;
c3[i][0]=0;
c4[i][0]=0;
}
for(i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
c1[i][0]+=b[i][j]*a1[j][0];
c2[i][0]+=b[i][j]*a2[j][0];
c3[i][0]+=b[i][j]*a3[j][0];
c4[i][0]+=b[i][j]*a4[j][0];
}
}
clrscr();
initgraph(&gdriver, &gmode, "Z:\TC\BGI");
line(c1[0][0],c1[1][0],c2[0][0],c2[1][0]);
line(c2[0][0],c2[1][0],c3[0][0],c3[1][0]);
line(c3[0][0],c3[1][0],c4[0][0],c4[1][0]);
line(c4[0][0],c4[1][0],c1[0][0],c1[1][0]);
break;
case 3: double sx,sy;
cout<<"Enter x scaling factor\n";
cin>>sx;
cout<<"Enter y scaling factor\n";
cin>>sy;
double e[3][3]={sx,0,0,0,sy,0,0,0,1};
for( i=0;i<3;i++)
{
c1[i][0]=0;
c2[i][0]=0;
c3[i][0]=0;
c4[i][0]=0;
}
for(i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
c1[i][0]+=e[i][j]*a1[j][0];
c2[i][0]+=e[i][j]*a2[j][0];
c3[i][0]+=e[i][j]*a3[j][0];
c4[i][0]+=e
[i][j]*a4[j][0];
}
}
clrscr();
initgraph(&gdriver, &gmode, "Z:\TC\BGI");
line(c1[0][0],c1[1][0],c2[0][0],c2[1][0]);
line(c2[0][0],c2[1][0],c3[0][0],c3[1][0]);
line(c3[0][0],c3[1][0],c4[0][0],c4[1][0]);
line(c4[0][0],c4[1][0],c1[0][0],c1[1][0]);
break;
}
getch();
}
0 comments :