An Interpretation of the affine matrix transformation of Silverlight Rotation

Source: Internet
Author: User

The MatrixTransform attribute changes are required for the Silverlight rotation animation. This is a function of the affine matrix transformation, which allows the image to produce visual rotation. Its principle is not to change the position of an image, but to change the coordinate system of the plane x and y, indirectly changing the coordinates of the image, how to accurately control the image rotation by rotating the coordinate system is the role of the matrix of the affine transformation:

Affine Transformation)

Resolve an affine transformation matrix Ma to Ms × Mr × Mt. In this formula, Ms is the scaling matrix, Mr is the rotation matrix, and Mt is the translation matrix. The affine matrix should not contain mistangent components. Specific operations can be divided into several steps.

1. Obtain the translation matrix
In the Ms × Mr × Mt process, the translation factor at Ma41, Ma42, and Ma43 will not change, so:
1 0 0 0
Mt = 0 1 0 0
0 0 1 0
Ma41 Ma42 Ma43 1

2. Extraction of the scale-in matrix
For Ma = Ma × Mt ^-1, Ma = Ms × Mr
Mrx × Mry is equivalent to the angle represented by rotating Mry around the X axis for each row vector of Mrx, and a new result matrix is formed by the three new rows, mrx is the transformation matrix in which the vector rotates around the X axis. The sum of squares of each vector component is 1, so the model of the row vector is 1. The length of the line vector is not changed after multiplied by the Mry of the rotation matrix, that is, the model is 1, therefore, the sum of squares of each line (row vector) in the result matrix of Mrx × Mry is 1.
Extend the preceding conditions. A Mr can be expressed as Mry × Mrx × Mrz × Mrx ^-1 × Mry ^-1, or another representation, however, all representation forms can be expressed as the product of Mrx, Mry, Mrz, and its inverse matrix. According to the above analysis, the sum of squares of each line of the Mr vector component must be 1.
Because Ms is a diagonal matrix, the form of Ms × Mr is as follows:
B11 0 0 0 a11 a12 a13 0
0 b22 0 0 x a21 a22 a23 0
0 0 b33 0 a31 a32 a33 0
0 0 0 1 0 0 1
Mr MS
The formula above is calculated, and the sum of squares of the Mr row vector component is 1:
B11 = Ma11 ^ 2 + Ma12 ^ 2 + Ma13 ^ 2 + Ma14 ^ 2;
B22 = Ma21 ^ 2 + Ma22 ^ 2 + Ma23 ^ 2 + Ma24 ^ 2;
B33 = Ma21 ^ 2 + Ma22 ^ 2 + Ma23 ^ 2 + Ma24 ^ 2;
So far, Ms is used.

3. Obtain the rotation matrix
In the above calculation, the Ma value is changed to Ms × Mr.
First find Ms ^-1, then Mr = Ms ^-1 × Ma = Ms ^-1 × Ms × Mr;

The AffineTransform class describes a two-dimensional affinettransform function, which is a linear transformation between two-dimensional coordinates and two-dimensional coordinates to maintain the "straight" of two-dimensional images, that is to say, after the transformation, the straight line or straight line will not bend, the arc or the ARC) and the "Parallel" (in fact, it means to keep the relative positional relationship between two-dimensional images unchanged, parallel lines or parallel lines, the intersection of the intersection line remains unchanged. I still remember the "shape preserving transformation/angle preserving transformation" that I learned in my sophomore year. Mathematics is king !). Affine transformations can be achieved through the combination of a series of atomic transformations, including Translation, scaling, Flip, Rotation, and Shear ).
 
This type of transformation can be represented by a 3 × 3 matrix, and the last row is (0, 0, 1 ). The transformation matrix converts the original coordinates (x, y) to the new coordinates (x ', y'). Here, the original coordinates and the new coordinates are regarded as the three-dimensional column vectors with the last line (1, the original column vector left multiplication transformation matrix obtains the new column vector:
 
[X'] [m00 m01 m02] [x] [m00 * x + m01 * y + m02]
[Y'] = [m10 m11 m12] [y] = [m10 * x + m11 * y + m12]
[1] [0 0 1] [1] [1]

 
Typical affine transformations:
 

  1. Public StaticAffineTransform getTranslateInstance (DoubleTx,DoubleTy)

Shift transform: Move each point to (x + tx, y + ty). The transformation matrix is:
[1 0 tx]
[0 1 ty]
[0 0 1]
Translation transformation is a kind of "rigid-body transformation". rigid-body transformation, which is an ideal object that does not produce deformation, translation certainly does not change the shape of a two-dimensional image. Similarly, the following "Rotation Transformation" is also a rigid body transformation, and "Scaling" and "miscut" will change the shape of the image .)
 

  1. Public StaticAffineTransform getScaleInstance (DoubleSx,DoubleSy)

Zoom-in and zoom-in or zoom-out the abscissa of each point to sx times, vertical to sy times, and transform the Matrix:
[Sx 0 0]
[0 sy 0]
[0 0 1]

 

  1. Public StaticAffineTransform getShearInstance (DoubleShx,DoubleShy)

Cut transform, transformation matrix:
[1 shx 0]
[Shy 1 0]
[0 0 1]
It is equivalent to the combination of a transverse shear and a longitudinal shear.
[1 0 0] [1 shx 0]
[Shy 1 0] [0 1 0]
[0 0 1] [0 0 1]
The "shear transformation", also known as the "staggered transformation", refers to the nature similar to the Quadrilateral instability. Have you ever seen the small shops on the street? Imagine the process of pulling the diamond formed by the iron strip above, that is, the process of "miscutting .)
 

  1. Public StaticAffineTransform getRotateInstance (DoubleTheta)

Rotate and transform. The target image rotates the theta radian clockwise around the origin. The conversion matrix is:
[Cos (theta)-sin (theta) 0]
[Sin (theta) cos (theta) 0]
[0 0 1]

 

  1. Public StaticAffineTransform getRotateInstance (DoubleTheta,DoubleX,DoubleY)

Rotate and transform. The target image uses (x, y) as the axis to rotate the theta radian clockwise. The transformation matrix is:
[Cos (theta)-sin (theta) x-x * cos + y * sin]
[Sin (theta) cos (theta) y-x * sin-y * cos]
[0 0 1]
It is equivalent to the combination of two Translation Transformations and one origin Rotation Transformation:
[1 0-x] [cos (theta)-sin (theta) 0] [1 0 x]
[0 1-y] [sin (theta) cos (theta) 0] [0 1 y]
[0 0 1] [0 0 1] [0 0 1]




























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.