Gdiplus [48]: igpmatrix (iii) Matrix Rotation

Source: Internet
Author: User
A matrix rotation angle is associated with four data types: M11, M12, m21, and m22. The calculation formula is as follows:
 
┏ ┓ ┃ Cos (r) sin (r) 0 ┃-sin (r) Cos (r) 0 ┃ DX dy 1 ┃ ┗ ┛ // The r here is not the angle of the radian; The radian calculation method is: r = angle * PI/180.

  

The following two paragraphsProgramThe above formula is compared and tested:

// Var M: igpmatrix; begin M: = tgpmatrix. create; M. rotate (90); showmessagefmt ('% F % F', [M. elements. m11, M. elements. m12]); // 0.00 1.00 showmessagefmt ('% F % F', [M. elements. m21, M. elements. m22]); //-1.00 0.00 M. reset; M. rotate (-30); showmessagefmt ('% F % F', [M. elements. m11, M. elements. m12]); // 0.87-0.50 showmessagefmt ('% F % F', [M. elements. m21, M. elements. m22]); // 0.50 0.87end; // var R: single; M11, M12, m21, m22: single; Begin R: = 90 * PI/180; M11: = cos (r); M12: = sin (r); m21: =-sin (r); m22: = cos (r); showmessagefmt ('% F % F ', [M11, M12]); // 0.00 1.00 showmessagefmt ('% F % F', [m21, m22]); //-1.00 0.00 R: =-30 * PI/180; M11: = cos (r); M12: = sin (r); m21: =-sin (r); m22: = cos (r); showmessagefmt ('% F % F', [M11, M12]); // 0.87-0.50 showmessagefmt (' % F % F', [m21, m22]); // 0.50 0.87end;

  

Observe the rotation effect of a point (90 degrees from blue to red ):


Uses gdiplus; procedure merge (Sender: tobject); var graphics: igpgraphics; pen: igppen; brush: igpsolidbrush; matrix: igpmatrix; I: integer; Pt: tgppointf; begin clientwidth: = 300; clientheight: = 200; pen: = tgppen. create ($ ffe0e0e0); brush: = tgpsolidbrush. create ($ ff0000ff); graphics: = tgpgraphics. create (handle); // draw the coordinate system graphics. clear ($ ffffffff); for I: = 1 to clientwidth Div 10 do graphics. drawline (pen, tgppoint. create (I * 10, 0), tgppoint. create (I * 10, clientheight); for I: = 1 to clientheight Div 10 do graphics. drawline (pen, tgppoint. create (0, I * 10), tgppoint. create (clientwidth, I * 10); pen. color: = $ ffb0b0b0; graphics. drawline (pen, tgppoint. create (clientwidth Div 2, 0), tgppoint. create (clientwidth Div 2, clientheight); graphics. drawline (pen, tgppoint. create (0, clientheight Div 2), tgppoint. create (clientwidth, clientheight Div 2); // Pan coordinate system graphics. translatetransform (clientwidth Div 2, clientheight Div 2); graphics. pixeloffsetmode: = pixeloffsetmodehalf; graphics. drawellipse (pen,-2,-2, 5, 5); // if there is a vertex (80,-40), draw the vertex PT in blue. initialize (80,-40); graphics. drawline (pen, tgppointf. create (0, 0), Pt); graphics. fillrectangle (brush, PT. x-2, PT. y-2, 5, 5); // Rotate 90 degrees, redraw This vertex graphics with red. rotatetransform (90); graphics. pixeloffsetmode: = pixeloffsetmodehalf; brush. color: = $ ffff0000; graphics. drawline (pen, tgppointf. create (0, 0), Pt); graphics. fillrectangle (brush, PT. x-2, PT. y-2, 5, 5); end;
 
   
 

Rotating and transforming igpmatrix. Rotate () or igpgraphics. rotatetransform has a circle (0, 0;

Igpmatrix. rotateat () can rotate around a specified point, for example:


 
Uses gdiplus; Procedure tform1.formpaint (Sender: tobject); var graphics: igpgraphics; matrix: igpmatrix; pen: igppen; rect: tgprect; begin graphics: = tgpgraphics. create (handle); pen: = tgppen. create ($ ffd0d0d0, 2); rect. initialize (50, 30, 80, 80); graphics. clear ($ ffffffff); graphics. drawrectangle (pen, rect); matrix: = tgpmatrix. create; matrix. rotateat (45, tgppointf. create (rect. X + rect. width/2, rect. Y + rect. height/2); graphics. multiplytransform (matrix); pen. color: = $80ff0000; graphics. drawrectangle (pen, rect); end;

  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.