Matrix learning-in the space of basic knowledge, let's leave a topic: if an image rotates around a certain point P (A, B), first you need to translate the coordinate system to this point and then rotate it, then, the rotated image is moved back to the original coordinate origin.
We need three steps:
- Translation-- Shifts the coordinate system to P (A, B );
- Rotate-- Rotate the image with the origin as the center;
- Translation-- Translate the rotated image back to the original coordinate origin;
Compared with the aforementioned geometric changes of images (Basic geometric changes of images ),Pan -- rotate -- panThis kind of geometric change that requires multiple types of images is calledCompound changes of images.
For a given image, F1, F2, F3 ..... , FN, their change matrices are T1, T2, T3 ..... , TN, image composite change matrix t can be expressed as: t = TnTn-1... T1.
According to the above principle, the change matrix sequence of θ rotating around a certain point (a, B) is:
Based on the above formula, we will give a simple example: rotate around (100,100) 30 degrees (SIN 30 = 0.5, cos 30 = 0.866)
Float F [] = {0.866f,-0.5f, 63.4f, 0.5f, 0.866f,-36.6f, 0.0f, 0.0f, 1.0f };
Matrix =New Matrix();
Matrix.Setvalues(F );
The rotated image is as follows:
Android provides us with a simpler method, as follows:
MatrixMatrix = newMatrix();
Matrix.Setrotate(30,100,100 );
Actual results after matrix operation:
This is exactly the same as the matrix obtained through the formula.
Here we provide another method to achieve the same effect:
FloatA = 100366f, B = 100366f;
Matrix = newMatrix();
Matrix.Settranslate(A, B );
Matrix.Prerotate(30 );
Matrix.Pretranslate(-A,-B );
I will explain it in detail later.
Using a similar method, we can also get:Ratio of relative P (A, B) to [SX, sy] Change Matrix
Http://www.moandroid.com /? P = 1805