Sunday, October 16, 2011

C Graphics : Rotation in 2D transformation


void rotate(int *x,int *y,double th)

{

double trans[3][3]={1,0,0,0,1,0,0,0,1};

double a[3][1]={0,0,1};

double c[3][1];

int i,j,k;





th=th*M_PI/180;

trans[0][0]=cos(th);

trans[0][1]=-sin(th);

trans[1][0]=sin(th);

trans[1][1]=cos(th);

a[0][0]=*x;

a[1][0]=*y;



for(i=0;i<3;i++)

{

for(j=0;j<1;j++)

{

c[i][j]=0;

for(k=0;k<3;k++)

{

c[i][j]+=trans[i][k]*a[k][j];

}

}

}







*x=abs(c[0][0]);

*y=abs(c[1][0]);





}

No comments:

Post a Comment