#include #include #include #include #define lin(a,b,c,d) line(320+(a),240-(b),320+(c),240-(d)) #define scarb(x,y) a*x+c-a*c,b*y+d-b*d #define sctr(x,y) a*x+c,b*y+d #define refline(x,y) x*p - y*q + c*sin(ang),-q*x - p*y + c + c*cos(ang) void house(int a,int b,int c,int d,int e,int f,int g,int h,int i,int j) { lin(a,b,c,d); lin(c,d,e,f); lin(e,f,g,h); lin(g,h,i,j); lin(i,j,a,b); } main() { int left,top,right,bottom,hei,a,b,c,d,gd=DETECT,gm; double ang,m,p,q; initgraph(&gd,&gm,"c:\\tcpp30\\bgi"); lin(-320,0,320,0); lin(0,-240,0,240); printf("Enter room topleft x and y:"); scanf("%d%d",&left,&top); printf("Enter room bottomright x and y:"); scanf("%d%d",&right,&bottom); printf("Enter height of roof:"); scanf("%d",&hei); //left=top=40; right=80; bottom=20; hei=30; house(left,top,left,bottom,right,bottom,right,top,(left+right)/2,top+hei); printf("Enter scale factors for x and y:"); scanf("%d%d",&a,&b); printf("Enter co-ord of arb pt for translation:"); scanf("%d%d",&c,&d); house(sctr(left,top),sctr(left,bottom),sctr(right,bottom), sctr(right,top),sctr( ((left+right)/2),(top+hei) ) ); printf("Enter scale factors for x and y:"); scanf("%d%d",&a,&b); printf("Enter co-ord of arb reference pt:"); scanf("%d%d",&c,&d); house(scarb(left,top),scarb(left,bottom),scarb(right,bottom), scarb(right,top),scarb( ((left+right)/2),(top+hei) ) ); printf("Enter m and c for line y=mx+c:"); scanf("%lf%d",&m,&c); ang=-atan(m); //the following two lines represent optimizations p=cos(ang)*cos(ang)-sin(ang)*sin(ang); q=2*sin(ang)*cos(ang); house(refline(left,top),refline(left,bottom),refline(right,bottom), refline(right,top),refline( ((left+right)/2),(top+hei) ) ); getch(); return 0; }