Although the previous study of linear algebra and graphics principles, but in the actual encounter matrix or puzzled for a while, today through to colleagues to find a little way, the summary is as follows:
Matrix is mainly used to scale, pan, rotate and tilt the plane, to simplify matrix transformation, Android encapsulates a series of methods for matrix transformation, including the Pre series method: Prescale,pretranslate,prerotate, Preskew,set Series Method: Setscale,settranslate,setrotate,setskew,post Series method: Postscale,posttranslate,postrotate,postskew.
By multiplying the transformation matrix with the original matrix to achieve the purpose of the transformation, for example:
Translation:
Rotating:
Scaling:
One thing to note: In the original matrix is 3*1 matrix, we can extend it into a 3*3 matrix, otherwise the following will be related to the subsequent multiplication operation is not established, even in the later times we can be seen as a 1*3 matrix, which does not affect the actual transformation effect.
Never understood why to set pre,set and post three kinds of transformation operations, I always think that only through the post operation can complete all the transformation, and then through the access to relevant information and colleagues of the guidance, there are some superficial understanding, of course, the current understanding is still vague, even wrong, I hope to share and correct the mistakes I may have through the blog.
The Pre method represents the pre-multiplication of the Matrix, for example: The transformation matrix is a, and the original matrix is the meaning of the B,pre method a*b
The Post method represents the matrix after multiplication, for example: The transformation matrix is a, the original matrix is the meaning of the B,post method is B*a
- Matrix.prescale (0. 5f, 1);
- Matrix.pretranslate (ten, 0);
- Matrix.postscale (0. 7f, 1);
- Matrix.posttranslate ( 0);
Equivalent to:
Translate (0), scale (0.5f, 1) and scale (0.7f, 1), translate (15, 0)
Note: The pre-invoke operation is executed first, and then the post operation is executed after the call.
Once the set method is called, all transformations in the previous matrix are emptied, for example:
- Matrix.prescale (0. 5f, 1);
- Matrix.setscale (1, 0. 6f);
- Matrix.postscale (0. 7f, 1);
- Matrix.pretranslate ( 0);
Equivalent to
Scale (1, 0.6f) and scale (0.7f, 1), translate (0)
Matrix.prescale (0.5f, 1) will not work.
The following is a personal understanding and does not guarantee that it must be correct:
If the matrix obtained through Getmatrix () is a matrix of cells that has not undergone any transformations, or is a matrix that has previously been called SetMatrix, then we can use only one of the post series methods or the pre-series method to complete a variety of transformation operations, Because at this point we only use the pre or POST method to define the various transformation order.
But if the matrix we get is a non-cell matrix, and the matrix has not yet called SetMatrix to be applied to the actual, then we may need both the pre and post methods to implement the transformations we need, For example, C is obtained through Getmatrix and satisfies the previously described matrix, at this time if I want to make some transformations before the existing transformation, only the pre method can do, if C is a matrix that performs Postscale operation, At this point I want to pan before the Postscale, that only call pretranslate, so when the call SetMatrix will be pretranslate operation, and then Postscale operation. The premise of this must be that the first scale after the translate and the first translate after the scale to get a different transformation effect.
Personally think that the above analysis results are likely to have some deviations, such as which heroes find errors and please correct me ~ ~
Android in Matrix's pre post Set method understanding (Reprint Source: Linux community ZJMDP)