CG ch4
CG ch4
Polishwala
Chapter – 4 : Transformation
Matrices and matrix operations are very important mathematical tools which are used in
computer graphics very extensively. Compact notation for describing sets of data and sets of
equations.
The number of rows and columns that a matrix has is called its dimension or its order. By
convention, rows are listed first; and columns, second. Thus, we would say that the dimension (or
order) of the above matrix is 3 x 4, meaning that it has 3 rows and 4 columns.
Numbers that appear in the rows and columns of a matrix are called elements or entries
of the matrix. In the above matrix, the element in the first column of the first row is 21; the
element in the second column of the first row is 62; and so on.
Statisticians use symbols to identify matrix elements and matrices.
Matrix elements: Consider the matrix below, in which matrix elements are represented entirely
by symbols.
By convention, first subscript refers to the row number; and the second subscript, to the
column number. Thus, the first element in the first row is represented by A11. The second element
in the first row is represented by A12. And so on, until we reach the fourth element in the second
row, which is represented by A24.
Matrices: There are several ways to represent a matrix symbolically. The simplest is to use a
boldface letter, such as A, B, or C. Thus, A might represent a 2 x 4 matrix, as illustrated below.
Square Matrix: A matrix is said to be a square matrix if the no. of rows and columns in the matrix
are same. That is m = n.
Unit Matrix: A matrix in which leading diagonal≠ elements are 1 and all
other elements are 0. That is aij = 1 (for i = j) and aij = 0 (for i j). It is always
denoted by I.
If we multiply the unit matrix with any other matrix
the resultant matrix remain the same matrix as it is. That
is A ∙ I = A. (both matrix should be of equal dimensions)
Then the product of A and I will be A itself.
Symmetric Matrix: A square matrix in which all aij = aji is called a symmetric matrix. Following is
an example of such matrix.
Skew Symmetric Matrix: A square matrix in which all aij = - aji is called a skew symmetric
matrix. Following is an example of such matrix.
Transposition Matrix: A matrix in which all rows are converted to columns and all columns are
converted to rows is known as a transposition matrix of the original matrix. Which means a
transposition matrix of (m X n) direction will be of (n X m). it is denoted by a superscript T.
Orthogonal Matrix: Matrix A is said to be an orthogonal matrix if it produces unit matrix when it
is multiplied by its own transpose.
T
A∙A =I
Zero / Null Matrix: If a matrix A is having all elements as 0 then the matrix A is said to be a Zero
or Null Matrix.
Diagonal Matrix: A diagonal matrix is a special kind of symmetric matrix. It is a symmetric matrix
with zeros in the off-diagonal elements. Two diagonal matrices are shown below.
Note that the diagonal of a matrix refers to the elements that run from the upper left corner to the
lower right corner.
Scalar Matrix: A scalar matrix is a special kind of diagonal matrix. It is a diagonal matrix with
equal-valued elements along the diagonal. Two
examples of a scalar matrix appear below.
It is a unary operation. Which mean it can be performed only on one matrix at a time. If
matrix A is of m X n dimensions and c is a constant number or a scalar than scalar multiplication
of the matrix A with scalar c would be obtained by multiplying all the entries of matrix with the
scalar c, which means for all aij with c where 1≤ i ≤ m and 1≤ j ≤ n. That is c ∙ A = caij.
For e.g.
For performing addition and subtraction of two matrices, they must be of same dimension.
If matrices A and B are of same dimensions, then the summation of these two matrices would be
obtained by adding all corresponding entries of matrices together, which can be represented as
follows:
A + B = aij + bij where 1≤ i ≤ m and 1≤ j ≤ n.
Similarly the subtraction A – B can be obtained by subtracting all entries of matrix B from
the corresponding entry of matrix A.
Two matrices can be multiplied to each other on one condition that is no. of columns of the
matrix on the left side should be equal to no. of rows of matrix on the right side of the
multiplication operator. So the matrix A of m X n dimension can be multiplied to matrix B of p X q
dimensions only if n = p. the product of two matrices is denoted by
(∙) dot operator. So it can be written as follows:
Amxn X Bpxq = Cmxq (only if n = p)
It can be derived by,
abij = ai1b1j + ai2b2j + . . . +ainbpj
For e.g.
The determinant of a square matrix is a function depending upon the scalar of matrix. It is
denoted by det(A) or |A|.
|A| = a11 (a22 ∙a33 - a23 ∙a32) - a12 (a21 ∙a33 - a23 ∙a31) + a13 (a21 ∙a32 - a22 ∙a31)
The sign pattern to be consider is as follow for the calculation of the determinants of
different entries.
If the determinant of the matrix is a non-zero then it is called non-singular matrix, and if it
4 SUTEX BANK COLLEGE OF COMPUTER APPLICATIONS & SCIENCE, AMROL, SURAT
601 – Computer Graphics Asst. Prof. Viral B. Polishwala
Let A and B two matrices of order mXm, then they are called inverse of each other if,
A∙B = B∙A = I
The method of find the inverse is too lengthy to perform. The method of reduction is known
as Gauss Elimination Method. It works on the principle “If a non-singular matrix A is converted into
an identity matrix by a series of row and/or column operations, then the same series of operations
performed on the identity matrix converts it into the inverse matrix of A.”
Let A be the m X m non-singular matrix to be inverted. The augmented matrix would be,
Solution: First of all we have to find the determinant of matrix A, for checking
whether it is a non-singular matrix or not.
|A| = 1(5-18) -2(2-3) + 5(12-5) = -13 + 2 + 35 = 24 ≠ 0, matrix A is non-singular matrix.
Now we have to perform row and column operation on the matrix to find the inverse.
, R3-R1
, R1-5R3
4.3 Transformation
In 2D graphics we are using different objects like lines, curves, polygons, circle, etc.; all
these objects need to be altered at many situations. The alterations which can be applied are
moving them, rotating them as well as enlarging or reducing them. These processes are termed as
Scaling, Rotations and Translations in computer Graphics. For performing these actions it needs
certain basic geometry, so they are also known as geometric transformations.
4.3.1 Scaling
Scaling transformation is used to alter the size of the given object, which is defined in term
of the scaling factor. The scale factor defines that how much bigger or smaller the object would
look after the scaling. To alter the object in horizontal direction the scale factor Sx is used whereas
to alter the object in the vertical direction the scale factor Sy is used. The scaling transformation is
performed by multiplying the coordinates (x,y) with the scaling factor Sx and Sy respectively.
Mathematical representation of transformation of the original coordinates (x,y) into scaled
coordinates (x’,y’) is:
x’ = Sx∙x and y’= Sy∙y
To scale a polygon object, the transformation is performed on all the vertices of the
polygon. To enlarge the size of the polygon horizontally, the X-coordinates of all the vertices need
to be multiplied with the enlarging factor. Similarly for reducing the size in horizontal direction all
the vertices should be multiplied with the reduction factor (i.e. for reduce the size to half we have
to multiply the coordinates with 0.5). It is similar with the vertical alterations whether enlarging or
reducing. So it can be given in form of matrix as below:
scaling factors Sx, Sy are greater than 1then the object will be enlarged in horizontal or vertical
directions respectively. If these values are between 0 and 1 then the object will be reduced in
respective directions. And if the values are 1 then the scaling matrix will be a unique matrix as well
as there will be no change in the object. When the scaling is equal in both horizontal and vertical
directions then the value of Sx = Sy. This type of scaling transformation is known as uniform scaling
whereas in other situations it is known as differential scaling.
When we are performing the scaling transformation on the object, we have to check that
after performing the transformation the object does not lose its position. In all the graphics
applications it requires to keep the object at its place which may be represented as (xk,yk) will not
changed after the transformation. So this transformation can be given by the equations:
x’ = xSx + (xk - xkSx) and y’ = ySy + (yk - ykSy) or
x’ = xSx + xk (1 - Sx) and y’ = ySy + yk (1 - Sy)
It can be written in matrix form as below:
Where xk (1 - Sx) and yk (1 - Sy) are constant terms which are added to the original scale
transformations.
Above equation can work well with the objects with straight lines whereas of the object is
having curves like circle and ellipse this equation can’t be used. In such situations parameter like
radius for the circle and semi-major and semi-minors in case of ellipse will be used.
4.3.2 Translation
Translation an object means moving the object from one place to other in 3 different ways
as below:
• Translation in horizontal direction- parallel to horizontal axis – X
• Translation in vertical direction- parallel to vertical axis – Y
• Translation in both the direction simultaneously.
For understanding the translation let assume we have a point (x,y) to be translated in
horizontal direction, means it will be parallel to the X-axis by Tx units. So this point can be obtain
by adding the Tx to X-coordinate, so the coordinates after transformation will be,
x’ = x + Tx and y’ = y
Similarly, if we translate point (x,y) in vertical direction parallel to the Y-axes by Ty unit, so
the coordinates after translation can be given as:
x’ = x and y’ = y+ Ty
In both above mentioned equations Tx and Ty are translation factors for translating a point
in the X and Y directions respectively. In general it can be written as:
Where P’ is a 1X2 row matrix of coordinates of the translated point, P is the 1X2 row matrix
of coordinates of original point and T is also
1X2 row matrix of translation factors.
The translation transformation is called a rigid body transformation since the Euclidian
distance between any two coordinates are never changes during the translation.
Here the translation is performed on each and every vertices of the object to translate the
object. When new vertices are found the object is redrawn with the translated points. Other objects
like circle, ellipse etc. when there is no straight lines in the objects certain parameters are used for
performing the translations like centre point of circle.
Rotation is the mostly used transformation. In this transformation an object moves on the
circular path about its origin. It requires two major parameters direction of rotation and angle of
the rotation. The rotation can be performed in anti-clockwise or clockwise directions by a given
angle Ө.
The rotation in 2D graphics is performed around some origin point which is known as
rotation point. This rotation can also be described as rotation around an axis which is called
rotation axis. This rotation axis passes through rotation point and is perpendicular to the XY-plane.
Let’s assume a point (x,y) is to be rotate anti-clockwise. In fig.4.6 the point (x’,y’) is rotated
point, as a result of rotation transformation in anti-clockwise direction with angle Ө relative to the
origin (0,0). Ø is an angle of point P from X-axis. So according to simple trigonometric principles;
value of x and y can be obtained as:
In equation (6), Ra is the rotation transformation matrix for rotating a point P in anti-
clockwise direction with angle Ө relative to origin.
Similarly, we can derive the equation to rotate a point in clockwise direction by angle Ө
about the origin.
Here we are rotating point P(x,y) in the clockwise direction, and angle will be Ө.
4.3.4 Shearing