#include #include #include #include float t[3][3]; void rotate(float th) { t[0][0]=t[1][1]=cos(th*3.14159/180); t[2][2]=1; t[0][1]=sin(th*3.14159/180); t[1][0]=-t[0][1]; t[2][0]=t[2][1]=t[1][2]=t[0][2]=0; } void tran_point(int oldx,int oldy,int *newx, int *newy) { *newx=(int)(t[2][0]+t[0][0]*oldx+t[1][0]*oldy); *newy=(int)(t[2][1]+t[0][1]*oldx+t[1][1]*oldy); } void main() { int GraphDriver; /* The Graphics device driver */ int GraphMode; /* The Graphics mode value */ struct viewporttype vp; float deg; struct point { int x,y; } p1,p2,p3,p4; printf("give me the first point--->"); scanf("%d %d",&p1.x,&p1.y); printf("give me the second point--->"); scanf("%d %d",&p2.x,&p2.y); printf("give me the rotate angle degree -->"); scanf("%f",°); getche(); GraphDriver = DETECT; /* Request auto-detection */ initgraph( &GraphDriver, &GraphMode, "" ); setcolor(YELLOW); line(p1.x,p1.y,p2.x,p2.y); getche(); setcolor(CYAN); rotate(deg); p3.x=p2.x-p1.x; p3.y=p2.y-p1.y; /* translate p1 --> (0,0) , so p2 == */ tran_point(p3.x,p3.y,&p4.x,&p4.y); line(0,0,p3.x,p3.y); getche(); setcolor(GREEN); line(0,0,p4.x,p4.y); getche(); line(p1.x,p1.y,p4.x+p1.x,p4.y+p1.y); getche(); closegraph(); /* Return the system to text mode */ }