Amazon banner

Friday, 17 August 2012

C PROGRAM TO DEMONSTRATE SHEARING TRANSFORMATION

/* C PROGRAM TO DEMONSTRATE SHEARING TRANSFORMATION*/

/* AUTHOR : DEEPAK MAHAKALE 3RD YEAR IT SRCOEM, NAGPUR*/
#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<graphics.h>
void main()
{
int poly[30],a[9][3],b[3][3],c[9][3],poly2[30];
int x=0,y=0,p,i,j,k,xc,yc,ch;
int gd=DETECT,gm;
clrscr();
initgraph(&gd,&gm,"C:/TC/BGI");
xc=getmaxx()/2;
yc=getmaxy()/2;

setcolor(1);
setbkcolor(15);
setfillstyle(6,3);

printf("\n Enter number of points : ");
scanf("%d",&p);
j=0;
for(i=0;i<p*2;i+=2)
{
printf("\n Enter cordinate point x%d and y%d : ",j+1,j+1);

scanf("%d",&poly[i]);
scanf("%d",&poly[i+1]);
j++;
}
poly[p*2]=poly[0];
poly[p*2+1]=poly[1];


for(i=0;i<p*2;i+=2)
{
poly2[i]=xc+poly[i];
poly2[i+1]=yc-poly[i+1];

}
poly2[p*2]=poly2[0];
poly2[p*2+1]=poly2[1];

fillpoly(p+1,poly2);

line(0,yc,xc*2,yc);
line(xc,0,xc,yc*2);


printf("\n Shearing of : \n 1. x \n 2. y \n 3. Both\n enter choice : ");
scanf("%d",&ch);
if(ch==1)
{
printf("\n Enter x shear value : ");
scanf("%d",&x);
}
if(ch==2)
{
printf("\n Enter y shear value : ");
scanf("%d",&y);
}
if(ch==3)
{
printf("\n Enter x shear value : ");
scanf("%d",&x);
printf("\n Enter y shear value : ");
scanf("%d",&y);
}


j=0;
for(i=0;i<p;i++)
{
 a[i][0]=poly[j];
 a[i][1]=poly[++j];
 a[i][2]=1;
 ++j;
}

if(ch==1)
{
    for(i=0;i<3;i++)
    {
     for(j=0;j<3;j++)
     {
       b[i][j]=0;
       if(i==j)
       {
       b[i][j]=1;
       }
     }
    }
    b[1][0]=x;

}
else if(ch==2)
{
    for(i=0;i<3;i++)
    {
     for(j=0;j<3;j++)
     {
       b[i][j]=0;
       if(i==j)
       {
       b[i][j]=1;
       }
     }
    }
    b[0][1]=y;

}
else if(ch==3)
{
    for(i=0;i<3;i++)
    {
     for(j=0;j<3;j++)
     {
       b[i][j]=0;
       if(i==j)
       {
       b[i][j]=1;
       }
     }
    }

    b[1][0]=x;
    b[0][1]=y;

}
for(i=0;i<p;i++)
{

   for(j=0;j<3;j++)
   {
   c[i][j]=0;
     for(k=0;k<3;k++)
     {
 c[i][j]=c[i][j]+a[i][k]*b[k][j];
     }
   }

 }
printf("\n\n\n\n\n\t After Shearing : ");


for(i=0,j=0;i<p;i++,j+=2)
{
poly[j]  =xc+c[i][0];
poly[j+1]=yc-c[i][1];
}
poly[j]  =poly[0];
poly[j+1]=poly[1];

setfillstyle(9,2);
fillpoly(p+1,poly);

getch();
closegraph();
}





No comments:

Post a Comment