Tuesday, July 26, 2011

2D-Shearing


#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
#include<stdlib.h>
class Trans
{
public:
int tx,ty,n,i,j,z;
int a[50],b[50];
float sh;
void get();
void show();
};
void Trans::get()
{
cout<<"\n  Enter the Side of the Polygan:";
cin>>n;
cout<<"\n Enter the "<<2*n<<"  Co-ordinates Value:";
for(i=0;i<2*n;i++)
cin>>a[i];
fillpoly(n,a);
getch();
cout<<"\n\n Enter the Y Reference  Vector:";
cin>> tx;
cout<<"\n\n Enter the X Reference  Vector:";
cin>>ty;
cout<<"\n\n Enter the Shearing Point:";
cin>>sh;
}
void Trans::show()
{
while(1)
{
cout<<"\n\t\t\t1.X Shear";
cout<<"\n\t\t\t2.Y Shear";
cout<<"\n\t\t\t3. Exit";
cout<<"\n Enter your Choice:";
cin>>z;
switch(z)
{
case 1:
cleardevice();
cout<<"\n Before Shear:";
fillpoly(n,a);
getch();
cleardevice();
cout<<"\n\n\n After After";
for(i=0;i<2*n;i+=2)
{
b[i]=a[i]+(sh*(a[i+1]-tx));
b[i+1]=a[i+1];
}
fillpoly(n,b);
break;
case 2:
cleardevice();
cout<<"\n Before Shear:";
fillpoly(n,a);
getch();
cleardevice();
cout<<"\n\n\n After After";
for(i=0;i<2*n;i+=2)
{
b[i]=a[i];
b[i+1]=a[i+1]+(sh*(a[i]-ty));
}

fillpoly(n,b);
break;
case 3:
exit(0);
break;
}
}
}
void main()
{
int v=DETECT,c=0;
initgraph(&v,&c,"");
cleardevice();
Trans w;
int q;
while(1)
{
cout<<"\n\t\t\t\t SHEARING";
cout<<"\n MENU:";
cout<<"\n\n\t\t\t 1.Shearing:";
cout<<"\n\n\t\t\t 2.Exit";

cout<<"\n Enter Your Option:";
cin>>q;
switch(q)
{
case 1:
w.get();
w.show();
break;
case 2:
exit(0);
default:
cout<<"\n\t\t\t Invalid!!!";
break;
}
getch();
}
}

No comments:

Post a Comment

Please put your valuable comments