The graph on a plane can be stored as a set of vertices on the computer. The graph can be obtained by drawing the vertices and connecting the vertices with straight lines (triangular fragments and rasterization operations in the GPU pipeline). If there are n Vertex, they are stored in a matrix, the coordinates of the vertices are stored in the first row of the matrix, the coordinates are stored in the second row, and each pair of successive vertices are connected by a straight line.
For example, to store the coordinates of a vertex at
For the triangle of, store the number pairs corresponding to each vertex as a column of the matrix:
A copy of the additional vertex is stored in the last column, so that the previous vertex can be drawn back ,
Which is along the following figure
The trajectory is drawn as shown in the figure below:
By changing the position of the vertex and redrawing the graph, the graph can be transformed. If the transformation is linear, it is a transformation that satisfies the following two principles:
- After the origin is changed, it remains at the origin
- It is still a straight line after the straight line transformation
It can be achieved by matrix multiplication, such a series of transformations can get an animation.
For example, the first
Zoom in and zoom out (scaling)
For the shape
The linear operator, when the time is enlarged, when the time is reduced, operator matrix L may be expressed as
As shown below:
The second
Reflection
If it is the transformation of the vector about the axis symmetry, it satisfies the above two principles, it is a linear transformation, a linear operator, and can be expressed as a matrix A.
because
and so
Similarly, the transformation of the mirror image on the y-axis is
As shown below:
The third type, rotation
Rotation
Let L be a transformation that rotates the vector from the initial position , which is also a linear transformation, which satisfies the above two principles. The transformation matrix is:
The last one, translation
Translation
The translation transformation of the vector is like
Is a constant vector.
If , the origin will move, so it is not a linear transformation. And cannot be expressed as a matrix. However, in computer graphics, all transformations are required to be expressed as the multiplication of matrices. Around this problem, a new coordinate system is introduced, which becomes a homogeneous coordinate. This new coordinate can express the translation as a linear transformation.
The homogeneous coordinate system is constructed by equating the middle vector with the vector whose first two coordinates are the same as the middle and the vector, and the third coordinate is 1.
When it is necessary to draw a point represented by a homogeneous coordinate vector , simply ignore its third coordinate and draw an ordered pair .
The current transformation discussed above must now be expressed as a matrix. To this end, the matrix can be expanded by adding elements in the third row and third column of the identity matrix, for example, a magnifying matrix
Matrix replaced by
Note:
If the transform will translate the vector in the vector
Then the matrix representation of the transformation can be obtained in the homogeneous coordinate system by simply replacing the elements in the third column of the two rows of the matrix with elements . That is
Here is a comprehensive rendering. The shear transformation in G2D design is actually a linear space transformation:
end