Compilation Environment: VS2017
Compilation framework: MFC
Experimental content: Displays a triangle and rotates, scales, and pans around the center
Experimental steps:
1. Open the VS2017 and create an MFC project, as described in: http://www.cnblogs.com/junjunjun123/p/8811150.html
2. Add the following code to the new execution program
1 voidcmfcapplication1view::ongeo_transfor ()2 {3 //TODO: Add Command handler code here4 5CDC *pdc=GetDC ();6 Doubleq= the;//Clockwise rotation angle (in degrees)7 DoubleC=0.5, d=0.5;//x, y zoom multiplier8 DoubleE= -, f=0;//x, y shift amount9 Ten //Convert to radians Oneq=q/ the*3.1415926; A - //Initial triangle -CPoint pts[3]; the //a triangle after a geometric transformation -CPoint zf[3]; - //storage of temporary initial coordinates - Doubletj[3]; + //storing temporary converted coordinates - Doublesx[3]; + A //assigning an initial value to a coordinate point atpts[0].x= -, pts[0].y= -; -pts[1].x= -, pts[1].y= -; -pts[2].x= $, pts[2].y= -; - //Calculate the center coordinate of a triangle (A, B) - DoubleA= (pts[0].x+pts[1].x+pts[2].x)/3; - DoubleB= (pts[0].y+pts[1].y+pts[2].Y)/3; in - //Composite transformation matrix that combines the set of geometric transformation parameters into this transformation matrix to Doubler[3][3]= +{{C*cos (q), D*sin (q),0}, -{-c*sin (q), D*cos (q),0}, the{c* (-a*cos (q) +b*sin (q)) +a+e, d* (-a*sin (q)-b*cos (q)) +b+f,1}}; * $ Panax Notoginseng for(intI=0;i<3; i++)//I denotes the first point of a triangle - { the +tj[0]=pts[i].x; Atj[1]=pts[i].y; thetj[2]=1; + for(intj=0;j<3; j + +)//J denotes column J of the Matrix - { $sx[j]=tj[0]*r[0][j]+tj[1]*r[1][j]+tj[2]*r[2][j]; $ - } -zf[i].x=sx[0]; thezf[i].y=sx[1]; - }Wuyi output the initial graphics thePdc->polygon (pts,3); - Graphics After transformation of the output set WuPdc->polygon (ZF,3); - About /*CRect Rectdlg; $ GetClientRect (RECTDLG);//Gets the size of the form - int h=rectdlg.height (); - int w=rectdlg.width (); - */ A +}
Use C + + to rotate, scale, and pan a graph