#include<graphics.h>
#include<conio.h>
#include<stdio.h>
#include<math.h>
typedef struct origin
{
int x,y;
}PT;
#define r 3
#define c 3
double mat[r][c];
PT pt[4];
void funtransform(int p);
void funrotate(double a);
void funsetidentity(double mm[r][c]);
void main()
{
int gd=DETECT,gm,i,j,p,a,ch;
clrscr();
printf("\n\n Rotate Object Prog");
printf("\n \t.....................");
printf("\n\n 1>Line:");
printf("\n\n 2>triangle");
printf("\n\n 3>Rectangle:");
printf("\n.............");
printf("\n\n Enter Your choice:-");
scanf("%d",&ch);
switch(ch)
{
case 1:
p=2;
break;
case 2:
p=1;
break;
case 3:
p=3;
break;
case 4:
p=4;
break;
default:
p=0;
}
if(p==0)
exit();
for(i=0;i<p;i++)
{
printf("\n Enter X- %d and Y-%d",i,i);
scanf("%d %d",&pt[i].x,&pt[i].y);
}
printf("\n Enter Angle:-");
scanf("%d",&a);
clrscr();
initgraph(&gd,&gm,"c:\\tc\\bgi");
outtextxy(280,10,"Original Object");
switch(ch)
{
case 1:
line (pt[0].x,pt[0].y,pt[1].x,pt[1].y);
break;
case 2:
circle(pt[0].x,pt[0].y,50);
break;
/*case 3:
triangle(pt[0].x,pt[0].y,pt[1].x,pt[1].y,pt[2].x,pt[2].y);
break;*/
case 4:
rectangle(pt[0].x,pt[0].y,pt[2].x,pt[2].y);
break;
}
//fillpoly(p,pt);
getch();
cleardevice();
funsetidentity(mat);
funrotate(a);
funtransform(p);
outtextxy(100,10,"rotate Object");
switch(ch)
{
case 1:
line (pt[0].x,pt[0].y,pt[1].x,pt[1].y);
break;
case 2:
circle(pt[0].x,pt[0].y,50);
break;
/*case 3:
triangle(pt[0].x,pt[0].y,pt[1].x,pt[1].y,pt[2].x,pt[2].y);
break;*/
case 4:
rectangle(pt[0].x,pt[0].y,pt[2].x,pt[2].y);
break;
}
//fillpoly(p,pt);
getch();
closegraph();
}
void funsetidentity(double mm[r][c])
{
int i,j;
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{
if(i==j)
mm[i][j]=1.0;
else
mm[i][j]=0.0;
}
}
}
void funrotate (double a)
{
a=a*M_PI/180.00;
mat[1][1]=cos(a);
mat[1][2]=sin(a);
mat[2][1]=-sin(a);
mat[2][2]=cos(a);
}
void funtransform(int p)
{
int i,j;
double temp;
for(i=0;i<p;i++)
{
temp=(int)mat[1][1]*pt[i].x+mat[1][2]*pt[i].y+mat[1][3];
pt[i].y=(int)mat[1][2]*pt[i].x+mat[2][2]*pt[i].y+mat[2][3];
pt[i].x=(int)temp;
}
}