Friday 27 September 2013

2D Transformation - Shearing | Computer Graphics Lab Manual | IT department | Final Year





#include
#include
#include
#include
void display(int);
int a[10][4],b[10][4],r[4][4],n,ch,i,j,k;
int sh,shx,shy;

void main()
{
int gd=VGA,gm=VGAMED;
initgraph(&gd,&gm,"c:\\tc\\bgi");
while(1)
{ cout<<"\n1.Shearing about X axis";
cout<<"\n2.Shearing about Y axis";
cout<<"\nEnter your choice:";
gotoxy(30,21);
cin>>ch;
switch(ch)
{
case 1:
display(ch);break;
case 2:
display(ch);break;
case 3:
display(ch);break;
default:
cout<<"Thank you";
exit(0);
}}
getch();}
void display(int c){
cleardevice();
gotoxy(30,10);

  cout<<"\nEnter the number of lines:";
            cin>>n;
cout<<"\nEnter the points:\t";
for(i=1;i<=n;i++)
{
cin>>a[i][1]>>a[i][2];
a[i][3]=1;
}
cout<<"\nEnter shearing values:";
cin>>sh;
cleardevice();
setcolor(YELLOW);
for(i=1;i<=n-1;i++)
line(a[i][1],a[i][2],a[i+1][1],a[i+1][2]);
line(a[n][1],a[n][2],a[1][1],a[1][2]);
switch(c){
case 1:
outtextxy(400,450,"Shearing about X axis");
shx=sh;
r[1][1]=1;r[1][2]=0;r[1][3]=0;
r[2][1]=shx;r[2][2]=1;r[2][3]=0;
r[3][1]=0;r[3][2]=0;r[3][3]=1;
break;
case 2:
outtextxy(20,20,"Shearing about Y axis");
shy=sh;
r[1][1]=1;r[1][2]=shy;r[1][3]=0;
r[2][1]=0;r[2][2]=1;r[2][3]=0;
r[3][1]=0;r[3][2]=0;r[3][3]=1;
break;}
for(i=1;i<=n;i++)
{
for(j=1;j<=3;j++)
{
b[i][j]=0;
for(k=1;k<=3;k++)
{
b[i][j]=b[i][j]+(a[i][k]*r[k][j]);
}}}
for(i=1;i<=n-1;i++)
line(b[i][1],b[i][2],b[i+1][1],b[i+1][2]);
line(b[n][1],b[n][2],b[1][1],b[1][2]);
getch();
return;
}




No comments:

Don't You Think this Awesome Post should be shared ??
| 2D Transformation - Shearing | Computer Graphics Lab Manual | IT department | Final Year |
Back To Top Related Posts Plugin for WordPress, Blogger...