#include #include #include #include int t[3][3]; void translate(int tx,int ty) { t[0][0]=t[1][1]=t[2][2]=1; t[0][1]=t[1][0]=t[0][2]=t[1][2]=0; t[2][0]=tx; t[2][1]=ty; } void tran_point(int oldx,int oldy,int *newx, int *newy) { *newx=t[2][0]+t[0][0]*oldx+t[1][0]*oldy; *newy=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; int tx,ty; 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 translate (tx,ty)-->"); scanf("%d %d",&tx,&ty); getche(); GraphDriver = DETECT; /* Request auto-detection */ initgraph( &GraphDriver, &GraphMode, "" ); setcolor(YELLOW); line(p1.x,p1.y,p2.x,p2.y); getche(); setcolor(WHITE); translate(tx,ty); tran_point(p1.x,p1.y,&p3.x,&p3.y); tran_point(p2.x,p2.y,&p4.x,&p4.y); line(p3.x,p3.y,p4.x,p4.y); getche(); closegraph(); /* Return the system to text mode */ }