/*CSEMATTER.BLOGSPOT.IN
PROGRAM-TO PERFORM SCALING,SHEARING,ROTATION,TRANSLATION*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
void translation(float [3][3]);
void scaling(float [3][3]);
void display(float [3][3]);
void rotation(float [3][3]);
void shearingx(float [3][3]);
void shearingy(float [3][3]);
void multiply(float [3][3],float [3][3]);
int main()
{
int gd=DETECT,gm,i,j,k,choice;
float arr2[3][3];
initgraph(&gd,&gm,"C:\TC\bgi");
printf("Enter the values of x & y coordinates for 1st, 2nd, 3rd vertex");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
if(j==0)
scanf("%f",&arr2[i][0]);
if(j==1)
scanf("%f",&arr2[i][1]);
else
if(j==2)
arr2[i][2]=1;
}
}
display(arr2);
printf("enter the choice\n");
printf("enter the 1 for x-shearing\n");
printf("enter the 2 for y-shearing\n");
printf("enter the 3 for rotation\n");
printf("enter the 4 for translation\n");
printf("enter the 5 for scaling\n");
scanf("%d",&choice);
switch(choice)
{
case 1:
shearingx(arr2);
getch();
closegraph();
break;
case 2:
shearingy(arr2);
getch();
closegraph();
break;
case 3:
rotation(arr2);
getch();
closegraph();
break;
case 4:
translation(arr2);
getch();
closegraph();
break;
case 5:
scaling(arr2);
getch();
closegraph();
break;
}
}
void display(float arr2[3][3])
{
line(arr2[0][0],arr2[0][1],arr2[1][0],arr2[1][1]);
line(arr2[1][0],arr2[1][1],arr2[2][0],arr2[2][1]);
line(arr2[2][0],arr2[2][1],arr2[0][0],arr2[0][1]);
}
//SHEARING -X
void shearingx(float arr2[3][3])
{
int i,j,shx;
float arr3[3][3];
printf("Enter the value of x shearing");
scanf("%d",&shx);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
if(i==j)
arr3[i][j]=1;
if(i!=j)
arr3[i][j]=0;
}
}
arr3[1][0]=shx;
multiply(arr3,arr2);
}
//SHEARING -Y
void shearingy(float arr2[3][3])
{
int i,j,shy;
float arr3[3][3];
printf("Enter the value of y shearing");
scanf("%d",­);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
if(i==j)
arr3[i][j]=1;
if(i!=j)
arr3[i][j]=0;
}
}
arr3[0][1]=shy;
multiply(arr3,arr2);
}
void rotation(float arr2[3][3])
{float theta,arr3[3][3];
float theta1;
printf("Enter the value of theta");
scanf("%f",&theta);
theta1=(3.141592/180)*theta;
arr3[0][0]=cos(theta1);
arr3[0][1]=sin(theta1);
arr3[0][2]=0;
arr3[1][0]=-sin(theta1);
arr3[1][1]=cos(theta1);
arr3[1][2]=0;
arr3[2][0]=0;
arr3[2][1]=0;
arr3[2][2]=1;
multiply(arr3,arr2);
}
void scaling(float arr2[3][3])
{int sx,sy,i,j,k;
float arr3[3][3];
printf("Enter the value of x & y scaling");
scanf("%d %d ",&sx,&sy);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
if(i==0 && j==0)
arr3[i][j]=sx;
if(i==1 && j==1)
arr3[i][j]=sy;
if (i==2 && j==2)
arr3[i][j]=1;
if(i!=j)
arr3[i][j]=0;
}
}
multiply(arr3,arr2);
}
void translation(float arr2[3][3])
{int tx,ty,i,j,k;
float arr3[3][3];
printf("Enter the value of x & y-translation");
scanf("%d %d ",&tx,&ty);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
if(i==j)
arr3[i][j]=1;
else
arr3[i][j]=0;
arr3[2][0]=tx;
arr3[2][1]=ty;
}
}
multiply(arr3,arr2);
}
void multiply(float arr3[3][3],float arr2[3][3])
{int i,j,k;
float arr[3][3];
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
arr[i][j]=0;
} }
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
for(k=0;k<3;k++)
{arr[i][j]=arr[i][j]+arr2[i][k]*arr3[k][j];
} }}
display(arr);}
PROGRAM-TO PERFORM SCALING,SHEARING,ROTATION,TRANSLATION*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
void translation(float [3][3]);
void scaling(float [3][3]);
void display(float [3][3]);
void rotation(float [3][3]);
void shearingx(float [3][3]);
void shearingy(float [3][3]);
void multiply(float [3][3],float [3][3]);
int main()
{
int gd=DETECT,gm,i,j,k,choice;
float arr2[3][3];
initgraph(&gd,&gm,"C:\TC\bgi");
printf("Enter the values of x & y coordinates for 1st, 2nd, 3rd vertex");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
if(j==0)
scanf("%f",&arr2[i][0]);
if(j==1)
scanf("%f",&arr2[i][1]);
else
if(j==2)
arr2[i][2]=1;
}
}
display(arr2);
printf("enter the choice\n");
printf("enter the 1 for x-shearing\n");
printf("enter the 2 for y-shearing\n");
printf("enter the 3 for rotation\n");
printf("enter the 4 for translation\n");
printf("enter the 5 for scaling\n");
scanf("%d",&choice);
switch(choice)
{
case 1:
shearingx(arr2);
getch();
closegraph();
break;
case 2:
shearingy(arr2);
getch();
closegraph();
break;
case 3:
rotation(arr2);
getch();
closegraph();
break;
case 4:
translation(arr2);
getch();
closegraph();
break;
case 5:
scaling(arr2);
getch();
closegraph();
break;
}
}
void display(float arr2[3][3])
{
line(arr2[0][0],arr2[0][1],arr2[1][0],arr2[1][1]);
line(arr2[1][0],arr2[1][1],arr2[2][0],arr2[2][1]);
line(arr2[2][0],arr2[2][1],arr2[0][0],arr2[0][1]);
}
//SHEARING -X
void shearingx(float arr2[3][3])
{
int i,j,shx;
float arr3[3][3];
printf("Enter the value of x shearing");
scanf("%d",&shx);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
if(i==j)
arr3[i][j]=1;
if(i!=j)
arr3[i][j]=0;
}
}
arr3[1][0]=shx;
multiply(arr3,arr2);
}
//SHEARING -Y
void shearingy(float arr2[3][3])
{
int i,j,shy;
float arr3[3][3];
printf("Enter the value of y shearing");
scanf("%d",­);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
if(i==j)
arr3[i][j]=1;
if(i!=j)
arr3[i][j]=0;
}
}
arr3[0][1]=shy;
multiply(arr3,arr2);
}
void rotation(float arr2[3][3])
{float theta,arr3[3][3];
float theta1;
printf("Enter the value of theta");
scanf("%f",&theta);
theta1=(3.141592/180)*theta;
arr3[0][0]=cos(theta1);
arr3[0][1]=sin(theta1);
arr3[0][2]=0;
arr3[1][0]=-sin(theta1);
arr3[1][1]=cos(theta1);
arr3[1][2]=0;
arr3[2][0]=0;
arr3[2][1]=0;
arr3[2][2]=1;
multiply(arr3,arr2);
}
void scaling(float arr2[3][3])
{int sx,sy,i,j,k;
float arr3[3][3];
printf("Enter the value of x & y scaling");
scanf("%d %d ",&sx,&sy);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
if(i==0 && j==0)
arr3[i][j]=sx;
if(i==1 && j==1)
arr3[i][j]=sy;
if (i==2 && j==2)
arr3[i][j]=1;
if(i!=j)
arr3[i][j]=0;
}
}
multiply(arr3,arr2);
}
void translation(float arr2[3][3])
{int tx,ty,i,j,k;
float arr3[3][3];
printf("Enter the value of x & y-translation");
scanf("%d %d ",&tx,&ty);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
if(i==j)
arr3[i][j]=1;
else
arr3[i][j]=0;
arr3[2][0]=tx;
arr3[2][1]=ty;
}
}
multiply(arr3,arr2);
}
void multiply(float arr3[3][3],float arr2[3][3])
{int i,j,k;
float arr[3][3];
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
arr[i][j]=0;
} }
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
for(k=0;k<3;k++)
{arr[i][j]=arr[i][j]+arr2[i][k]*arr3[k][j];
} }}
display(arr);}
No comments:
Post a Comment