# A Theoretical Scientific Programming Framework for Application of Linear Matrix Transformation in Plane Computer Graphics

Authors: Mingcan Chen
Journal: Scientific Programming
 (2022)

---

## Abstract

Plane computer graphics are basic information carriers in many industrial scenarios, such as engineering simulation, automatic control, and software design. Plane computer graphics are generally a kind of digital signals guided by mathematical symbols, and each vertex of a plane computer graph forms a graph matrix. Therefore, linear matrix transformation serves as the most common algorithmic unit to realize various information processing operations. To improve ease of graph matrix computing in practical engineering scenarios, this paper proposes a theoretical scientific programming framework for application of linear matrix transformation in plane computer graphics. Firstly, theoretical basis of linear matrix transformation in homogeneous plane coordinates is displayed and analyzed. Then, the universal theorem about linear transformation of graph matrices is deduced, and corresponding proofs are also given. Finally, a case study is set up to demonstrate the main workflow of the proposed theoretical scientific programming framework. The simulative results reveal feasibility of the proposal.


---

## Body

## 1. Introduction

Geometric graphics transformation refers to some specific graphics process operations [1, 2], including movement of the defined graphics from one position to another [3], change of size and shape for graphics, or generation of complex graphics from existing graphics [4, 5]. And it is also named as graphics transformation for short [6, 7]. Graphics transformation can help deduce required graphics with the aid of two-dimensional or three-dimensional transformation operations [8, 9]. Figure 1 gives a typical example of 2D linear matrix transformation in plane space [10, 11]. Graphic transformation is usually realized via matrix transformation, and matrices used for transformation varies with different scenes [12, 13]. With the development of computer science and simulation modeling, graphics transformation is usually implemented by computer algorithms [14], forming the discipline of computer graphics [15]. In order to enhance engineering ease of digital signal processing in plane graphics [16], this work concentrates the theoretical scientific programming framework for application of linear matrix transformation in plane computer graphics [17, 18].Figure 1
A typical example of linear matrix transformation in plane space.Points are the basic elements of a graph [19]. In analytic geometry, points are represented by vectors [20, 21]. For example, points in two-dimensional space (plane) and in three-dimensional space are separately represented by(1)P2d∈x,y′,P3d∈x,y,z′.A planar (two-dimensional) figure or a spatial (three-dimensional) shape can be represented by a set of points (referred to as a set of points) [22, 23]. A planar graph can be represented by a matrix as follows:(2)Mat2d=x1x2⋯xny1y2⋯yn,where the set of vertices x1,y1′,x2,y2′,…,xn,yn′ are included and a three-dimensional graph can be represented by a matrix as follows:(3)Mat3d=x1x2⋯xny1y2⋯ynz1z2⋯zn.When the point set is represented by a matrix, the transformation of the point can be realized by the following linear transformation:(4)Ax=y,where x denotes the old point coordinates, A denotes the transformation matrix, and y denotes the new point coordinates. There is a one-to-one correspondence between linear transformation and matrix.


## 2. Plane Graph Transformation in Homogeneous Coordinates

First of all, it is supposed to illustrate four basic transformation types which are shown in Figure2: translation, scale, rotation, and skew [24, 25]. The commonly used transformation matrix of plane graphics contains four types: proportional transformation, symmetrical transformation, rotation transformation, and the translation transformation [26, 27].Figure 2
Four basic transformation types: translation, scale, rotation, and skew.Definition 1.
The proportional transformation is represented as the following format:(5)T=sx00sy,where sx and syare the proportional coefficient along the x-axis and y-axis, respectively, and they satisfy the condition: sx>0,sy>0. The different value setting of sx and sy leads to different scenes.(i)
Whensx=sy=1, it is a constant proportional transformation, that is, the figure is unchanged.(ii)
Whensx=sy>1, the figure magnifies proportionally along the two axes.(iii)
Whensx=sy<1, the figure shrinks proportionally along the two axes.(iv)
Whensx≠sy, the figure changes nonuniformly along the two axes, and the result is graphic distortion.Definition 2.
The symmetrical transformation is represented as the following format:(6)T=abcd,where a, b, c, and d are the symmetrical coefficients. The different value setting of a, b, c, and d leads to different scenes.(i)
Whena=1,d=−1,b=c=0, it is a symmetrical transformation about the X-axis.(ii)
Whena=−1,d=1,b=c=0, it is the symmetric transformation about the Y-axis.(iii)
Whena=−1,d=−1,b=c=0, it is the symmetric transformation about the origin.(iv)
Whena=d=0,b=c=1, it is the symmetric transformation about the straight line x−y=0.(v)
Whena=d=0,b=c=−1, it is the symmetric transformation about the straight line x+y=0.Definition 3.
The rotation transformation is represented as the following format:(7)T=cosθ−sinθsinθcosθ,where θ is the angle rotated around the origin of the coordinate. The different value setting of θ leads to different scenes.(i)
The value of this angle is positiveθ>0 when it rotates counterclockwise.(ii)
The value of this angle is negativeθ<0 when it rotates clockwise.Definition 4.
The translation transformation is represented as the following format:(8)T=x′=x+m,y′=y+n,or the following format:(9)x′y′=xy+mn.
As the translation transformation cannot be written in form ofAx=y, it is not with the linear type. In order to change translation transformation into linear transformation, we can uniformly use linear matrix operations to study plane graphic transformation [28]. The homogeneous coordinates are generated, in which n-dimensional vectors are represented by n+1-dimensional ones. When the homogeneous coordinate of the vector x1,x2,…,xn′ equals to hx1,hx2,…,hxn,h′, where h is a real number, the homogeneous coordinate representation of a vector is not unique, and different values of the homogeneous coordinate h represents the same point. A homogeneous coordinate 8,4,2′,4,2,1′ represents the point 4,2′ on the plane. Hence, the following definition can be deduced.Definition 5.
Whenh=1, the homogeneous coordinate x1,x2,…,xn,h′ is called as the normalized homogeneous coordinate.
After the introduction of homogeneous coordinates, translation transformation defined in Definition4 can be written as follows:(10)x′y′1=10m01n001xy1=x+my+n1.
It is a linear transformation, and the different value setting ofa, b, c, and d leads to different scenes.(i)
Whenm>0, the graph translates positively along the X-axis.(ii)
Whenm<0, the graph translates negatively along the X-axis.(iii)
Whenn>0, the graph translates positively along the Y-axis.(iv)
Whenn<0, the graph translates negatively along the Y-axis.


## 3. Theorem and Proof for Plane Graphics Transformation

Theorem 1.
When the transformation matrix of the plane graph is denoted as follows:(11)T=abmcdn00s,the abcd causes proportional, symmetric, and rotational transformation of the planar graph, and mn causes the plane graph to produce translation transformation.Proof.
Supposing thaty=Tx, the following formula can be deduced:(12)x′y′1=abmcdn001xy1,where y, x, and T are separately represented as follows:(13)y=x′y′1=Y1,x=xy1=X1,T=abmcdn00s=T1T2T3T4.
According to the matrix block method, the following six formulas can be further deduced as follows:(14)Y=x′y′,X=xy,T1=abcd,T2=mn,T3=0,0,T4=s.
Then, they=Tx can be rewritten as follows:(15)Y1=TX1=T1T2T3T4X1=T1X+T2T3X+T4=T1X+T2T4.
Obviously,T1X is the basic transformation of two-dimensional graphics, thus translation transformation T1X+T2 can be deduced as follows:(16)T1X+T2=abcdxy+mn.
To sum up, the transformation of plane graphics can be represented by a unified matrix.(17)T=abmcdn00s.
The proof for Theorem1 is to be finished so far.
Points are often used in computer graphics, and if the position of point changes, so does the figure [29]. Therefore, if transform the graph, it is needed to change the point [30]. The effect of the product of a matrix and a vector in linear transformation provides a method of graphic transformation, which can be used to produce the effect of the graphic change in the computer [31, 32].
For a closed figure in a plane coordinate system, it is represented by a matrixx, and each column of x represents the coordinates of a vertex of the graph. To close the graph, the last column of x is the same as the first column [33]. In order to realize the translation of graphics by using linear transformation, a row with elements of 1 is added to matrix x so that the shape of matrix 3×n.
The following two transformation matrices are given as(18)M=10m01n001,R=cosθ−sinθ0sinθcosθ0001,for two transformation processes Y1=MX and Y2=RX, they can be separately explained as follows:(i)
Y1 is the transformation result of X, in which m is translated along the positive direction of the X-axis, n is translated along the positive direction of the Y-axis.(ii)
Y2 is the result of the inverse (clockwise) rotation of the θ angle of the graph X with the coordinate origin as the center.
The letter A is moved 15 up, 30 to the left, theπ/3 counterclockwise, and then 30 up, 20 to the right, then turn counterclockwise by 3/4π, and the MATLAB software is used to draw transformed graphics [34, 35]. The graphic matrix of the letter A can be constructed from Table 1. For this example, X is deduced as follows:(19)X=04610853.56.16.53.220014140011664.54.500111111111111.
From the meaning of the question, it can be seen that the transformation matrix of figure a moving up 15 and moving left 30, which can be represented as the following matrix:(20)M1=10−300115001.
And the transformation matrix can be represented as(21)R1=cosπ3−sinπ30sinπ3cosπ30001,where rotating counterclockwise of graph A is π/3. The transformation matrices of moving figure A up 30, 20 to the right, and 3/4π counterclockwise, respectively, are as follows:(22)M2=10200130001,R2=cos3π4−sin3π40sin3π4cos3π40001.
So, these three transformation matrices are respectivelyR1, M1, and R2M2, and one of them R2M2 is a combinatorial transformation.Table 1
Data sheet with letter A.
x04610853.56.16.53.220y014140011664.54.500


## 4. Scientific Programming Demo for the Case Study

Having analyzed basic linear matrix transformation theory and proved its efficiency, this section manages to give a practical scientific programming demo for the above case study. Its pseudo codes reveal major workflow of the proposed theoretical scientific programming framework, which is illustrated in Algorithm 1. Through such suggested theoretical scientific programming framework, it is expected to facilitate engineering practice in relevant areas. The proposed scientific programming demo for the above case study in MATLAB is given as follows:>>close all;>>X = [0,4,6,10,8,5,3.5,6.1,6.5,3.2,2,0;0,14,14,0,0,11,6,6,4.5,4.5,0,0;ones(1,12)];>>plot(X(1,:),X(2,:));% Draw the letter A figure hold on;>>M1 = [1,0,−30; 0,1,15; 0,0,1];>>Y1 = M1∗X;hold on;>>fill(Y1(1,:),Y1(2,:), “red”);%Draw the figure after the translation of the letter A.>>R1 = [cos(pi/3), −sin(pi/3),0];sin(pi/3),cos(pi/3),0;[0,0,1];>>Y2 = R1∗X;hold on;>>fill(Y2(1,:),Y2(2,:), “blue”);%Draw the figure after the letter A is rotated.>>M2 = [1,0,20; 0,1,30; 0,0,1];>>R2 = [cos(3∗pi/4), −sin(3∗pi/4),0];sin(3∗pi/4),cos(3∗pi/4),0;[0,0,1];>>Y3 = M2∗R2∗X;hold on;>>fill(Y3(1,:),Y3(2,:), “black”);%Draw the figure after the letter A is translated and rotated.Algorithm 1: Workflow of the proposed theoretical programming framework.
INPUT:X, M1, M2, R1, R2OUTPUT:Y1, Y2(1)
while Each graph do(2)
for Dimension: 1⟶3do(3)
Plot plane graph of letter A(4)
Define transformation matrixM1 for letter A(5)
Calculate transformation resultY1 for letter A(6)
Define transformation matrixR1 for letter A(7)
Calculate transformation resultY2 for letter A(8)
Define transformation matricesR2 and M2 for letter A(9)
Calculate transformation resultY3 for letter A(10)
Output graphics for letter A(11)
end for(12)
end whileRunning result of the above programming code leads to the graph in Figure3.Figure 3
Transformation diagram of letter A.


## 5. Conclusion

Plane graph transformation mainly includes proportion, symmetry, rotation, translation, and so on [36]. These transformations are unified into linear transformations under homogeneous coordinates and studied by the matrix [37]. This provides a unified transformation matrix method for coordinate transformation of two-dimensional, three-dimensional, and even high-dimensional space of geometric graphics, and these transformations can be easily combined [38]. The complexity of the transformation matrix is related to transformation steps, that is, the more steps, the more transformation matrix, which can produce the transformation of the complex graph [39, 40].



---

*Source: 3456302-2022-07-21.xml*