Tuesday, May 25, 2010

2D Transformation

#include
#include
#include
#include
#define MAXSIZE 3

class D_2
{
private:
double Points[MAXSIZE][MAXSIZE];
void Mult(double [MAXSIZE][MAXSIZE]);
void MultTwoMat(double [MAXSIZE][MAXSIZE],double [MAXSIZE][MAXSIZE]);
void Print();
int x,y;
public:
D_2();
void initialize();
void GetPoints();
void Draw(int);
void DrawCord();
void Translate();
void Rotate();
void Reflect();
void Display(double[MAXSIZE][MAXSIZE]);
void Shear();
void Scale_Fixed();
void Scale_Dir();
};


D_2::D_2()
{
for(int i=0;i>Points[i][j];
}
}
initialize();
}

void D_2::Mult(double temp[MAXSIZE][MAXSIZE])
{
int i,j,k;
double z[MAXSIZE][MAXSIZE];
for(i=0;i=0;i=i+50,j=j-50)
{
fillellipse(i,y/2,2,2);
fillellipse(j,y/2,2,2);
}
for(i=(y/2+50),j=(y/2-50);i<=x,j>=0;i=i+50,j=j-50)
{
fillellipse(x/2,i,2,2);
fillellipse(x/2,j,2,2);
}

outtextxy(x/2+3,y/2+4,"0");

outtextxy(x/2+45,y/2+5,"50");
outtextxy(x/2+95,y/2+5,"100");
outtextxy(x/2+145,y/2+5,"150");
outtextxy(x/2+195,y/2+5,"200");
outtextxy(x/2+245,y/2+5,"250");
outtextxy(x/2+295,y/2+5,"300");

outtextxy(x/2-65,y/2+5,"-50");
outtextxy(x/2-115,y/2+5,"-100");
outtextxy(x/2-165,y/2+5,"-150");
outtextxy(x/2-215,y/2+5,"-200");
outtextxy(x/2-265,y/2+5,"-250");
outtextxy(x/2-315,y/2+5,"-300");

outtextxy(x/2+5,y/2+45,"-50");
outtextxy(x/2+5,y/2+95,"-100");
outtextxy(x/2+5,y/2+145,"-150");
outtextxy(x/2+5,y/2+195,"-200");

outtextxy(x/2+5,y/2-50,"50");
outtextxy(x/2+5,y/2-100,"100");
outtextxy(x/2+5,y/2-150,"150");
outtextxy(x/2+5,y/2-200,"200");

}

void D_2::MultTwoMat(double temp[MAXSIZE][MAXSIZE],double
temp1[MAXSIZE][MAXSIZE])
{
int i,j,k;
double z[MAXSIZE][MAXSIZE];
for(i=0;i>Tx;
cout<<"Enter Translation Factor Along Y-Axis: "; cin>>Ty;
initialize();
for(int j=0;j>ang;
cout<<"Enter Point Of Rotation:X: "; cin>>xr;
cout<<"Y: "; cin>>yr;
initialize();
ang = (PI * ang)/180.0;
setcolor(YELLOW);
setfillstyle(SOLID_FILL,YELLOW);
fillellipse(x/2+xr,y/2-yr,2,2);
outtextxy(x/2+xr,y/2-yr-2," Point Of Rotation");

//Transformation Matrix
//Translate arbitrary point to origin then rotate then translate back.
for(int i=0;i>a;
cout<<"b: "; cin>>b;
cout<<"c: "; cin>>c;
if(b!=0)
{
yr = (-c/b);
xr = 0;
double m = -a/b;
ang = atan(m);

}
else
{
yr = 0;
xr = (-c/a);
ang = 22.0/14.0; // Angle = PI/2
}


initialize();
//Transformation Matrix
//Translate arbitrary point to origin then rotate then translate back.
for(int i=0;i>a;
cout<<"b: "; cin>>b;
cout<<"c: "; cin>>c;
cout<<"Enter Shearing Factor Along X-Axis: "; cin>>shx;
if(b!=0)
{
yr = (-c/b);
xr = 0;
double m = -a/b;
ang = atan(m);

}
else
{
yr = 0;
xr = (-c/a);
ang = 22.0/14.0; // Angle = PI/2
}


initialize();

//Transformation Matrix
for(int i=0;i>sx;
cout<<"Enter The Scaling Factor Along Y-Axis: "; cin>>sy;
cout<<"Enter Point Of Scaling:X: "; cin>>xr;
cout<<"Y: "; cin>>yr;
initialize();

//Transformation Matrix
for(int i=0;i>sx;
cout<<"Enter The Scaling Factor Along Y-Axis: "; cin>>sy;
cout<<"Enter The Direction Of Scaling: "; cin>>ang;
ang = (PI * ang)/180.0;
initialize();


//Transformation Matrix
for(int i=0;i>ch;
D1.initialize();
switch(ch)
{
case 1:
D1.GetPoints();
D1.Draw(GREEN);
getch();
break;

case 2:
cleardevice();
D1.Translate();
getch();
closegraph();
break;
case 3:
cleardevice();
D1.Scale_Fixed();
getch();
closegraph();
break;
case 4:
cleardevice();
D1.Rotate();
getch();
closegraph();
break;
case 5:
return;
default:
cout<<"WRONG CHOICE.";
getch();
break;
}
}while(1);
}



No comments:

Post a Comment