Matrix drawn by android view

Matrix coordinate transformation of points drawn by android view

First, let's review the knowledge of matrices in advanced mathematics (from Baidu Encyclopedia)

In mathematics, a matrix (Matrix) is a set of complex or real numbers arranged in a rectangular array[1], which originated from a square matrix composed of coefficients and constants of a system of equations. This concept was first proposed by Kelly, a British mathematician in the 19th century.
The number table with m rows and n columns arranged by m × n numbers aij is called a matrix with m rows and n columns, or m × n matrix for short. It is recorded as:
insert image description here
the m×n numbers are called elements of matrix A, referred to as elements for short, and the number aij is located in row i, column j of matrix A, called (i, j) elements of matrix A, and number aij is ( The matrix of elements i, j) can be denoted as (aij) or (aij)m × n, and the m×n matrix A is also denoted as Amn.
A matrix whose elements are real numbers is called a real matrix, and a matrix whose elements are complex numbers is called a complex matrix. A matrix whose number of rows and columns are both equal to n is called an n-order matrix or n-order square matrix [8].

The basic addition and subtraction of matrices will not be introduced here, and here is a special introduction to matrix multiplication . Matrix multiplication satisfies the following operation law: associative law: a(bc) = (ab)c left distributive law: (a+b)c =ac+bc right distributive law: c(a+b) = ca+cb!=ac+bc matrix multiplication does not satisfy commutative law ab!=ba





The conditions that must be met for matrix multiplication:
the number of rows of matrix a = the number of columns of matrix b,
insert image description here
the result matrix of matrix multiplication = each element of each row of matrix a * the sum of the results of each element of each column of matrix b

The mathematical knowledge about the matrix is ​​introduced here. The following introduces the use of the matrix in Android. The
matrix has 6 elements, each representing
insert image description here
a point. The matrix is ​​a 3*1 matrix

insert image description here

Then the result of matrix transformation for a point is
resultx = mscalex * prex+mskewx * prey+mtransx * 1
resulty = mscaley * prex+mskewy * prey+mtransy * 1

Matrix android provides an API for a path. Here I just show how I wrote it in a project, and I will do my own research.

              Matrix matrix = new Matrix();

               matrix.setScale(Float.valueOf(scaleX) * getScale(), Float.valueOf(scaleY) * getScale());
                path.transform(matrix);
                matrix.setRotate(Float.valueOf(rotate) * getScale());
                path.transform(matrix);
                matrix.setSkew(Float.valueOf(rotate) * getScale(), Float.valueOf(skew) * getScale());
                path.transform(matrix);
                matrix.setTranslate(Float.valueOf(translateX) * getScale(), Float.valueOf(translateY) * getScale());
                path.transform(matrix);

Supongo que te gusta

Origin blog.csdn.net/ligaoyuan8030/article/details/103642330
Recomendado
Clasificación