MATRICES
MATRICES
A Project Report
Submitted to
Department of Mathematics
Kathmandu Model Secondary School
Bagbazaar, Kathmandu, Nepal
Submitted by:
Garima Pradhananga
Shubham Piya
Sanjana Kumari Shah
Jigyasha Panta
Science M11
Under supervision: Mr. Santosh Basnet sir
ABSTRACT
The use of matrices in games has become a prevalent field of study in entertainment field and
gaming field as well. Matrices offer a powerful mathematical framework for transformations, like
translation, rotation, scale, skew which are used for the objects used in games in a compact and
efficient manner. This project report explores the projection of games in a flat screen using
matrices, taking numerous examples. The report begins with an introduction of matrices,
including their types, properties, and representations. It then delves into matrix projections due
to which the visualization of the scene on a 2d flat screen is possible.
2
DECLARATION
I solemnly affirm that I have completed the project report presented here under the guidance of
our Subject teacher, SB sir and it has not been previously submitted for any other examination.
All sources of information utilized in this report have been duly acknowledged through proper
referencing to the respective authors or institutions.
Signature:
Stream- Science
Section- M11
Date:
3
SUBJECT TEACHER'S RECOMMENDATION
I have supervised the project work report entitled ‘MATRIX AND ITS APPLICATION IN
GAMING’ which was submitted by the student named Jigyasha Panta of Kathmandu Model
College, Bagbazaar, Kathmandu. The report follows the procedure and format requirements set
by the Department of Mathematics and is being submitted as partial fulfillment of the internal
evaluation requirements for grade XII. Therefore, I recommend this report for evaluation.
Signature:
Date:
4
ENDORSEMENT
I hereby endorse the project work entitled ‘MATRIX AND ITS APPLICATION IN ENCODING
AND DECODING MESSAGES’ submitted by Jigyasha Panta in partial fulfillment of the
requirements of the internal evaluation of mathematics of grade XI.
Signature: Signature:
Date: Date:
5
ACKNOWLEDGEMENT
I am grateful for my humbleness and would like to acknowledge my regards to everyone who
helped me put these ideas together, well above all the simplicity and turning them into something
as strong as concrete. I would like to express my gratitude to the Head of Department
(Mathematics), Supervisor: Mr. Santosh Basnet sir, as well as the college administration for
providing me with this amazing opportunity to do this wonderful project on the topic, “Matrix
and its application in gaming” which encouraged me to do heaps of research where I got to
learn many new things. Any attempt at any level could not have been satisfactorily completed
without the support of my parents and siblings for their undivided support and interest, which
inspired and encouraged me to go on our way without whom I would be unable to complete my
project. Finally, I would also like to thank my group partners for their support and encouragement
to continue doing the work and helping me lots with the research.
Thank you!
Jigyasha Panta
6
TABLE OF CONTENTS
Table of Contents
Abstract ......................................................................................................................................................... 2
Declaration .................................................................................................................................................... 3
Subject Teacher’s Recommendation ............................................................................................................ 4
Endorsement ................................................................................................................................................. 5
Acknowledgement ........................................................................................................................................ 6
List of figures ................................................................................................................................................. 8
CHAPTER 1: INTRODUCTION ...................................................................................................................9-17
Background and Importance ..................................................................................................................... 9
Types of matrices .................................................................................................................................... 10
Properties ................................................................................................................................................ 13
Representation ........................................................................................................................................ 15
History ..................................................................................................................................................... 16
Motivation ............................................................................................................................................... 17
Limitation ................................................................................................................................................ 17
CHAPTER 2: USES OF MATRIX IN GAMING ...........................................................................................18-21
CHAPTER 3: CONCLUSION .......................................................................................................................... 22
Bibliography ................................................................................................................................................. 23
7
LIST OF TABLES/FIGURES
Fig: i Matrix (page 9)
8
CHAPTER 1: INTRODUCTION
Background:
For example: Here, matrix A holds 3 rows and 4 columns, and it can be named as 3 × 4 matrix
or 3-by-4 matrix. Matrices are useful in organizing and manipulating large amounts of data.
Matrices can be applied at any application that collects and manages data. Matrices have wide
applications in engineering, physics, economics, biology, genetics and in other branches or fields
of mathematics. In computer, matrices are applied in animation of images in movies and video
games. It also has important applications in computer graphics where matrices have been used
to represent rotations and other transformation of images.
Fig: i
While we can write code to calculate all those positions, having to iterate through each point and
calculate it is inefficient, both on the “writing code” level and the mathematical level. Due to a
quirk in how matrices work, we can multiply our points matrix by another matrix called a
“transformation matrix” and a computer can solve that quite easily and quickly – plus the
function can be reused for other cool applications like reflection (if the model needs to be
reflected over water or a mirror), scaling (making a bigger/smaller version of a model) or for
calculating things like drift and orbit.
9
TYPES OF MATRICES
1. Row matrix
A row matrix is a type of matrix having only one row. All the elements or entries of a row
matrix are arranged in a horizontal manner having all its elements in a single row but in multiple
columns. The order of the row matrix is 1 × n.
For example:
Fig: ii
2. Column matrix
A column matrix is a type of matrix that has only one column. All the elements or entries of a
column matrix are arranged in a vertical manner having all its elements in a single column but in
multiple rows. The order of the column matrix is n × 1.
For example:
Fig:iii
Fig: iv
10
4. Square matrix
A square matrix is a matrix with an equal number of rows and columns. The order of the
square matrix is n × n.
For example:
Fig: v
5. Diagonal matrix
A diagonal matrix is a square matrix that has zero elements or entries zero except the principal
or main diagonal.
For example:
Fig: vi
Fig: vii
11
7. Lower triangular matrix
A lower triangular matrix is a square matrix in which all the elements or entries above the
principal or main diagonal are zero.
For example:
Fig: viii
8. Symmetric matrix
A symmetric matrix is a type of matrix that is equal to its transpose.
For example:
A square matrix B=[aij] is said to be a symmetric matrix if and only if aij= aji for every value of
i and j i.e., a12= a21.
Fig: ix
Fig: x
12
Properties of matrices
• Commutative property
A+B=B+A
• Associative property
A + (B + C) = (A + B) + C
• Additive identity
A+0=0+A=A
• Additive inverse
A + (-A) = (-A) + A = 0
• Associative property
(AB)C = A(BC)
• Distributive property
A (B + C) = AB + AC
• Multiplicative identity
AI = IA = A, [ I is an Identity matrix]
13
3. Properties of scalar multiplication
Let A be a matrix and k be any constant, then the product of a constant with matrix is equal to
the product of the constant and all the elements or entries of matrix.
• Commutative property
kA = Ak
• Distributive property
k (A + B) = kA + kB and
(k + m) A = kA + mA, where k and m are scalars.
• Associative property
k(mA) = (km)A
Interchanging the rows and columns can result in transpose matrix. The transpose of the matrix
A is denoted as AT.
• (A^T) T = A
• (A + B) T = AT + BT
• (A × B) T = BT × AT
• (kA)T = kAT
(𝐴−1 )−1 = 𝐴
14
Representation of matrix
15
HISTORY
The beginning of concept of matrices go back to the second century. Over time, the concepts as
well as the ideas got developed.
The beginning of matrices had arisen through the study of systems of linear equations. The
Babylonians studied problems regarding simultaneous equations and some of them were
preserved in clay tablets so that other people could learn about it too. An important Chinese text
from 300 BC and 200 BC, "Nine Chapters of the Mathematical Art (Chiu Chang Suan Shu), gives
the first known example of the use of matrix methods to solve simultaneous equations.
Similarly, in the treatise's seventh chapter, "Too much and not enough", the concept of a
determinant appeared. Two millennia later, a Japanese mathematician Seki Kowa in 1683 looked
through the concept and finally invented it with his German contemporary Gottfried Leibnitz.
More uses of matrix like arrangement of numbers appear in chapter 8, "Methods of rectangular
arrays “in which a method is given for solving simultaneous equations using accounting board
that is identical to the modern matrix method of solution outlined by Carl Friedrich. The term
"matrix “then was coined by James Joseph Sylvester. However, it was his friend, the
mathematician, Arthur Cayley who developed the algebraic concept of matrices in two papers in
1850s.
The study of matrices gained momentum in the 20th century with the development of algebra.
The introduction of matrix notation and the study of matrix properties and operations by
mathematicians such as Arthur Cayley, Camille Jordan and William Rowan Hamilton laid the
foundation for the modern theory of matrices. Matrix theory found numerous applications in
various fields. Matrices are ideal for graphic representations and animating shapes. Also, matrices
are used for programming robots that can execute different tasks. It is also used in encoding and
decoding of messages, gaming, quantum physics, creating graphics and so on.
16
MOTIVATION
In games, matrices are the major mathematical tools to construct and manipulate a realistic
animation of a polygonal figure. Some of the basic and advanced matrix transformations are used
in video games. Understanding matrices is a necessity for programming 3D video games. Matrices
are used in computer games to represent transformations such as rotation, scaling, and
translation. For example, a matrix can be used to represent the position and orientation of an
object in 3D space. This allows the object to be provided correctly on the screen, taking into
consideration its position, rotation, and scale. Additionally, matrices can also be used to perform
more complex operations, such as projection and lighting calculations. Overall, matrices are a
powerful tool for computer graphics, and are used broadly in modern games to create realistic
and immersive environment.
LIMITATION
In Computer Graphics, matrices are used to represent many distinct types of data. Games that
involve 2D or 3D graphics rely on some matrix operations to display the game environment and
characters in game and to perform operations such as scaling, rotation, and translation. They
are also used in lighting and shading effects. However, it is of fixed size and its size cannot be
modified further which is a major disadvantage in the gaming field. Insertion and deletion
operations are costly if shifting occurs. Resizing a matrix can be time-consuming, especially if it
needs to be done frequently. Memory wastage may result if the specified matrix size is more
than what is required.
17
CHAPTER 2: USE OF MATRICES IN VIDEO
GAMES
1)Matrix projections
A mathematical operation known as projection must be carried out in order to visualize a scene
on a 2D flat screen. This mathematical transformation turns a 3D scene into a 2D image by
projecting the points or vertices that make up the scene’s objects onto the screen. The two
primary projection kinds are:
A point known as the vanishing point, or point at infinity, is where parallel lines converge in a
perspective projection, making the farthest objects appear smaller.
Regardless of the distance from the camera, things are the same size in an orthographic
projection. Even in the projected image, parallel lines in 3D space continue to be parallel.
It goes without saying that the type of game to utilize depends on the projection type.
The term “view frustum” refers to the volume that encapsulates all the spots on the screen that
could potentially be viewable. The camera’s eye placement determines this volume. The frustum
has a pyramidal truncation if the perspective projection is applied. This rectangular prism is
used in orthographic projection. The pyramid’s base is known as the far plane, and the
pyramid’s vertex corresponds to where the camera is positioned. Two planes parallel to the Z
axis are fixed to define the “view frustum”:
Distance plane
Nearby plane
The visual field is thus constrained by the six surfaces of the pyramid by these two planes, which
act as dividers.
The two planes that define the visual field are thus constrained by the six surfaces of the
pyramid trunk.
18
Fig: xi
Projecting the items that are in the ‘view frustum’ onto the game device’s screen is the key
challenge that needs to be overcome. Therefore, from a mathematical standpoint, it is necessary
to identify the forty-four matrix that represents the perspective or orthographic projection.
Calculating the coordinates of the on-screen images of the items that are inside the “view
volume” is made possible by the determination of the transformation matrix. The two
projections from the 3D scene onto the 2D screen can be achieved by the difficult calculation of
matrices, which will be covered in a subsequent article. Here, we keep things simple by only
exposing the matrices.
19
2)Systems of coordinates and matrices in Unity
It is first necessary to define a reference system (for instance, a Cartesian reference) before one
can indicate the position of an item in space. Therefore, each object’s position in relation to the
reference system is determined by its three coordinates.
In Unity, there are various reference space types, including world space, camera space, screen
space, and viewport. An established coordinate system is used in each space to specify how each
object is located.
Each object’s coordinates in the global space are related to the origin, a fixed point. The origin of
local space is the center of an object, which is obviously capable of motion. The vertices of the
object are specified with reference to this local origin. The position of the camera and, by
extension, the observer is indicated by the coordinates in camera space. A coordinate system is
established in the screen space to identify each point on the screen (coordinate UI) Using the
bottom left corner’s (0,0) origin as the starting point. A normalized coordinate system is used in
the Viewport, with coordinates (0,0) for the lower left point and (1,1) for the top right position.
For each object (Game Object) to which it belongs, the Unity Transform component carries vital
information, including:
Fig: xii
20
By using a linear transformation, or performing an algebraic operation on the matrices, it is
possible to determine the position of an item as described by its coordinates in relation to
another type of space. To change from one coordinate system to another, Unity has several
capabilities, such as:
1) TransformDirection
2) TransformPoint
3) TransformVector
4) InverseTransformDirection
5) InverseTransformPoint
6) InverseTransformVector
The first three change local space into global space, whereas the latter three do the opposite.
For instance, the Transform Direction command shifts a vector’s coordinates from local to
global space.
According to the current rotation of the object, the vector (1, 0, 0) in local space is one unit to
the right of the object whereas the vector (1, 0, 0) in global space is one unit to the right of the
global reference’s origin.
i. Camera.WorldToScreenPoint
ii. Camera.WorldToViewportPoint
iii. Camera.ScreenToViewportPoint
iv. Camera.ScreenToWorldPoint
v. Camera.ViewportToScreenPoint
vi. Camera.ViewportToWorldPoint
These functions provided by the Unity framework, as well as capabilities like these provided by
other video game engines, clearly demonstrate the vital relevance of the algebra of vectors and
matrices.
21
CHAPTER 3: CONCLUSION
- Unity uses a coordinate system to determine the position of objects in relation to a reference
point.
- Unity has capabilities and functions that allow for changing coordinates between local and
global space.
- Matrices are crucial in 3D programming and are used to transform an object’s coordinates.
- Unity provides functions like Transform Direction and TransformPoint for converting between
local and global space.
- Diverse types of projections, such as perspective and orthographic, are used to visualize scenes
on a 2D display.
22
BIBLIOGRAPHY
1. https://www.gameludere.com/2019/12/21/matrix-algebra-and-game-programming/
2. https://mathshistory.st-
andrews.ac.uk/HistTopics/Matrices_and_determinants/#:~:text=The%20beginnings%
20of%20matrices%20and,and%20development%20really%20got%20underway.
3. https://www.britannica.com/science/matrix-mathematics
4. https://byjus.com/question-answer/what-are-the-properties-of-matrix/
5. https://en.wikipedia.org/wiki/Matrix_representation#:~:text=Matrix%20representatio
n%20is%20a%20method,are%20stored%20contiguously%20in%20memory.
23