#include #include #include #include float t[3][3]; void shear(float t1,float t2) { t[0][0]=t[1][1]=t[2][2]=1; t[1][0]=t1; t[0][1]=t2; 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 x,y; struct point { int x,y; } p1,p2,p3,p4,p5,p6,p7,p8; 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 first point--->"); scanf("%d %d",&p5.x,&p5.y); printf("give me the second point--->"); scanf("%d %d",&p6.x,&p6.y); printf("give me the shearing y x -->"); scanf("%f %f",&y,&x); getche(); GraphDriver = DETECT; /* Request auto-detection */ initgraph( &GraphDriver, &GraphMode, "" ); setcolor(YELLOW); line(p1.x,p1.y,p2.x,p2.y); line(p5.x,p5.y,p6.x,p6.y); line(p1.x,p1.y,p5.x,p5.y); line(p2.x,p2.y,p6.x,p6.y); getche(); setcolor(CYAN); shear(y,x); p3.x=p2.x-p1.x; p3.y=p2.y-p1.y; /* translate p1 --> (0,0) , so p2 == */ p7.x=p6.x-p5.x; p7.y=p6.y-p5.y; /* translate p5 --> (0,0) , so p6 == */ tran_point(p3.x,p3.y,&p4.x,&p4.y); line(0,0,p3.x,p3.y); tran_point(p7.x,p7.y,&p8.x,&p8.y); line(0,0,p7.x,p7.y); getche(); setcolor(GREEN); line(0,0,p4.x,p4.y); line(0,0,p8.x,p8.y); getche(); line(p1.x,p1.y,p4.x+p1.x,p4.y+p1.y); line(p5.x,p5.y,p8.x+p5.x,p8.y+p5.y); line(p1.x,p1.y,p5.x,p5.y); line(p4.x+p1.x,p4.y+p1.y,p8.x+p5.x,p8.y+p5.y); getche(); closegraph(); /* Return the system to text mode */ }