#include<graphics.h>
#include<math.h>
#include<conio.h>
#include<iostream.h>constintNO=3;intcol=1;floata[3][3]={1,0,0,0,1,0,0,0,1};intpts[NO][3];voidchangepts(intp[NO][3]);voidmult(floatb[3][3]){floatc[3][3];for(inti=0;i<3;i++)for(intj=0;j<3;j++){c[i][j]=0;for(intk=0;k<3;k++)c[i][j]+=b[i][k]*a[k][j];}for(i=0;i<3;i++)for(intj=0;j<3;j++)a[i][j]=c[i][j];}voidtrans(intx,inty){floatb[3][3]={1,0,x,0,1,y,0,0,1};mult(b);changepts(pts);}voidscale(floatsx,floatsy){floatb[3][3]={sx,0,0,0,sy,0,0,1};mult(b);changepts(pts);}voidrot(floatangle){angle*=M_PI/180;floatb[3][3]={cos(angle),-sin(angle),0,sin(angle),cos(angle),0,0,0,1};mult(b);changepts(pts);}voidchangepts(intp[NO][3]){setcolor(col++);for(inti=0;i<NO;i++){intq[3];q[0]=(p[i][0]*a[0][0]+p[i][1]*a[0][1]+a[0][2]);q[1]=(p[i][0]*a[1][0]+p[i][1]*a[1][1]+a[1][2]);q[2]=1;for(intj=0;j<3;j++)p[i][j]=q[j];}a[0][0]=1;a[0][1]=0;a[0][2]=0;a[1][0]=0;a[1][1]=1;a[1][2]=0;a[2][0]=0;a[2][1]=0;a[2][2]=1;}voiddpoly(intp[NO][3]){for(inti=0;i<NO;i++)line(p[i][0]+getmaxx()/2,getmaxy()/2-p[i][1],p[(i+1)%NO][0]+getmaxx()/2,getmaxy()/2-p[(i+1)%NO][1]);}voidmain(){intgdriver=DETECT,gmode=VGAHI;initgraph(&gdriver,&gmode,"");for(inti=0;i<NO;i++){cout<<"Enter data for point "<<i+1;cin>>pts[i][0]>>pts[i][1];pts[i][2]=1;}cleardevice();dpoly(pts);intcho;do{cout<<"Enter 1 for translation\n\t2 for scaling\n\t3 for rotation ";cho=getche();cout<<endl;switch(cho){case'1':{intx1,y1;cout<<"Enter the value of x ";cin>>x1;cout<<"Enter the value of y ";cin>>y1;trans(x1,y1);dpoly(pts);break;}case'2':{floatsx,sy;intx1,y1;cout<<"Enter the value of x ";cin>>x1;cout<<"Enter the value of y ";cin>>y1;trans(-x1,-y1);cout<<"Enter the value of x scale";cin>>sx;cout<<<spanclass='cpp06'>"Enter the value of y scale"</span>;cin>>sy;scale(sx,sy);trans(x1,y1);dpoly(pts);break;}case'3':{intx1,y1;cout<<"Enter the value of x ";cin>>x1;cout<<"Enter the value of y ";cin>>y1;trans(-x1,-y1);floatangle;cout<<"Enter the angle in degrees ";cin>>angle;rot(angle);trans(x1,y1);dpoly(pts);break;}}}while(cho!='0');getch();}