Game Basic Episode Basic Math that Upholds the Game 4 (Matrix, Inverse matrix)
GCC Academy
Hello, everyone
This is Lee Deukwoo of Game Math
This time, I prepared a lecture about
matrix and inverse matrix, which serve an important role
in the computer graphics process that we will use
Matrix is divided into 4 types
First, we'll learn about what matrix is
and we'll learn about the method
of how it is calculated
Second, using the matrix
we'll learn about how to calculate and apply
the linear transformation we learned before
Third, when the linear transformation process
is connected to matrix
we'll learn about how it can be visualized
Once you learn about this principle
you'll be able to perform the wanted linear transformation
by designing it with a matrix
Finally, we'll learn about the product of matrix
Through the multiplication of matrices
we'll learn about why they allow us to calculate quickly
We'll learn about
the basic mechanism
For inverse matrix
I'll explain in two parts
First, I'll explain about the concept of inverse matrix
And second, I'll talk about
the calculation method of inverse matrix
Matrix
We'll first learn about the matrix
To define a matrix in simple terms
it's simply a rectangular frame
with numbers arranged in rows and columns
It's very simple, right?
Rather than the matrix itself having some meaning
the numbers are arranged inside the rectangular frame
And it's a tool that helps us
calculate something conveniently
I'll explain about this again later but
the linear transformation that we mentioned earlier
can be performed in a very easy, fast, and simple way
through this calculating tool
So when we assign the matrix
we can create them in two concepts
First is transformation
We can design the matrix in the concept of a function
Second, in the perspective of a vector within a space
we can use a matrix to perform the transformation we want
For the transformation in 2D vector space
the matrix is expressed with the size 2x2
Next, for the element of 2D vector space, which is 2D vector
it's expressed with a matrix with 2 rows and 1 column
So these matrices
can be used as a calculating tool
to transform a vector
into the form we want
First, I'll explain about the basic calculation method
of a matrix
Matrices have the adding operation
This can only applied to
matrices with the same size, rows, and columns
You just need to add the numbers in each location
Very easy, right?
So take the number corresponding to the location of "a"
add the two numbers together, assign it to that location
then you can perform the adding operation
Next, matrix and scalar
When a scalar value "k" is assigned to a matrix
you just need to perform a multiplication operation
by multiplying "k" to all elements
It's the same result as
multiplying scalar to a vector
Next, there's something called the transpose operation of a matrix
This is processed using superscript T
Transposing means switching
We're switching the rows and columns
Thus, rows become columns, and columns become rows
When a matrix with 3 rows and 2 columns gets transposed
it changes into a matrix with 2 rows and 3 columns
As you can see here, it flips to the other side
with "a" and "f" as the center point
Using "a" and "f" as the pivot
it flips to the other side
That's the transformation it undergoes
For square matrix, it looks the same even when you flip it
because the rows and columns are the same
Matrices with identical rows and columns are called square matrices
In that case, keep "a" and "d" as-is
and for the rest of the elements, "b" and "c"
flip them to the other side
then you have performed the transpose operation
That's called the transpose operation
The next important operation is the multiplication of matrices
This is a bit complicated
When there are two matrices like this
the one on the left is the row
We use its rows
For the one on the right, we use its columns
So criss-cross the rows and columns, and multiply
Multiply and add each element
Add the product of "a", "e" and the product of "b", "g"
Then you will end up with "ae" plus "bg"
For the second element, multiply "a" and "f"
and add it to the product of "b" and "h"
For the third one, row 2 column 1
Multiply "c" and "e" and add it to the product of "d" and "g"
For the fourth, final one, row 2 column 2
Multiply "c" and "f", and add the product of "d" and "h"
Just like that, cross the rows and columns
and add the elements after multiplying them
The multiplication operation is complicated
so first-timers will have to practice many times
Through these kinds of operation system
we can calculate mechanically
It's good to know about the characteristics of operations beforehand
The characteristic of the multiplication operation of matrices
is that it doesn't satisfy the commutative property
That is, when matrices "a" and "b" are multiplied in reverse order
we can't guarantee that the value will be the same
We'll take a look
When "a" and "b" are defined as matrices, like the following
the first element will be ae+bg
But if we switch these two
it becomes ea+fc
Since the commutative property is valid for ea
the first is the same, but the second is bg
and we get cf here
So we can see that the value is different
For the value to be the same even with the switched order
a particular condition would have to be established
Anyways, for normal cases
the commutative property is not satisfied
as you should know
However, switching the order
switching the multiplication order when calculating
And by order, I mean the direction is the same
Commutative property is when the direction itself
the multiplying direction itself is flipped
For associative property, the direction is the same
but it's about whether multiplication is in the front or the back
It's about whether we're multiplying the front first or the back first
That's the difference
So as long as we maintain the same direction
whether we multiply the front first or the back first
the result will be the same
I will explain about these properties of a matrix later
but this gives you a very important, big advantage
The property of a matrix satisfies the associative property
Since it satisfies like this
whether we multiply first or later
you can understand that the results are the same
The third thing we need to know
is the transpose of the products of matrices
When multiplied products are transposed
it's the same thing as multiplying
the transposed matrices
What that means, is that
when we multiply the matrices "A" and "B"
the transpose matrix of this would be ehfg
And the transpose of this would be adbc
But multiplying first
has the same results as
transposing, and then multiplying
Then we end up with this kind of formula
We're going to use it later, so it would be good to know
Next, although it is complicated, it also satisfies the distributive property
which uses the multiplication and addition of matrices
The calculation is complicated, so I didn't write it down but
just know that it is satisfied
Actually, it's good to know but
among what we're going to learn right now
distributive property won't be used
That's why I didn't write it down
We now learned about the characteristics
of basic operations
Then why do we use matrices?
I've briefly mentioned earlier, but
in linear transformation, maintaining the structure of the vector space as-is
while also having linearity
and transforming into a new space, this process itself
can be corresponded to a matrix, and that's the merit
Therefore, rather than calculating each linear transformation
simply using matrices
to organize them and conduct multiplication
we quickly can perform the wanted linear transformation
Because of that merit, we use matrices
We'll learn about how matrices
correspond to linear transformation
Earlier, we said that vector functions, like the following
satisfy linearity
When we combine two independent elements, x and y
to make a vector, and change that in some form
and when we make the first and second elements
with this combination of linear equation, with no impurities
then in the vector space R2
it's a linear transformation that has correspondence to
R2
Same thing with this, when I define
an arbitrary matrix as abcd
and an arbitrary vector as x, y
then based on the rule of multiplication of matrices
the result of the matrix is like the following
The first element is ax+by
and the second element is cx+dy
It is made into a vector
If you look here
the original x, y corresponds to this vector
and then the result
of using the vector function
is the same as
ax+by, cx+dy
Then this matrix, abcd, ultimately
corresponds x and y to a point in ax+by, cx+dy
in a linear transformation
Thus, it conducts the role of a function
Then now we're ready to conduct linear transformation
using these matrices
Before getting into it
there are two ways to express a matrix
There's the column major matrix, and the row major matrix
Usually, when you use computer graphics
or make an independent game engine
there are two ways to use the matrix
The normal way we use is
treating the vector as the column during calculation
And we make the matrix into a square matrix
Make the function into a square matrix
The result is also a column vector, as we call it
We can see that it is made into a column vector
This notation method is called OPEN GL
In graphic libraries
or when we conduct matrices in normal math
we often use this method
Since this expresses the vector as column
it's called a column major matrix
However, there's also a way to express based on the row
This method expresses the vector as a row
And
when we use DirectX or something
to implement the game engine ourselves
or when we take a look at the source of business engines
some cases are written as row major matrix
When we use the vector as a row
we spread out x, y horizontally
and its order comes to the front
And when we look at abcd
this one is arranged in horizontal order
but here, abcd is arranged in a vertical order
Then the direction would change now
Finally, for the result of calculating this
since we calculate the row and column
ax+by is correct
And then cx+dy, the values are the same
However, this has a result of a column
but this has a result of a row
Then let's say
we made a new vector on a vector
When ax+by, cx+dy is set as v'
and when x, y is set as v
it gets this form of equation
in column major matrix
But when we change this into row major
the result, v'
v', expressed in column major, is now changed
into row major
Then changing the v' of column major into a row major
ultimately means transposing
Transposing this is taking Av
the equation we used earlier to make this
this equation of multiplying matrix A and v
will be like transposed in the result
What that becomes is
transposing a product of matrices
is the same as switching the two
and multiplying the transpose of each
Therefore, for this equation
put the transposed v^T first
and put the transposed matrix A in the back
It's the same result of calculation
When we use the vector as the column
here's the difference between using it as the column
and using it as the row
The matrix that actually conducts the transformation
has a simple difference
in the transposition
The only difference is the A and A^T
Therefore, using row major versus column major
doesn't make a big difference
For the matrix that actually conducts transformation
row major method is simply transposing
the matrix used in column major
Same goes for the other way
If you want to use it as row major
same thing, simply transpose it
The one we'll talk about in this lesson
is column major
but if you are using other DirectX or referring to
source codes of Unreal Engine, and you find a matrix
they will be expressed as row major
Since they're different, you might think that you have to
learn it again from the start, but it will be solved by simply
transposing it
I summarized it here because it would be good to know
To see how matrices that conduct these linear transformation
get changed
we'll draw an actual picture
Before the transformation
let's say there's a vector space
The x, y here is
Actually, the x and y
are combined in a uniform, equal relationship
with no interference
So for the arbitrary point x, y
if we think about the structure of how it is created
e1 and e2 of a standard basis vector
were each multiplied by x and y, then added together
Through a combined equation like this
the vector was created in the vector space
Then some space was changed
Actually, a space contains infinite elements
therefore, tracking down all the infinite elements
and analyzing each correspondence
is actually close to impossible
However, if we analyze the movement of the basis vector
which is the foundation holding up the space
then even if we don't check every single element
we can visually predict
how the space will change
Through those predictions, we can have the wanted effect
by tracking backwards
So the original space had two foundations
That was, the standard basis vector, E1 and E2
And it was changed
The point in the changed space
was changed like this
The first standard basis vector corresponding to (1, 0) is (a,c)
and the second standard basis vector is (b, d)
Then the vector (1, 1) made by
combining these with 1 to 1 proportion
changes into this form
All the vectors in the space change this way
Of course, the elements are infinite, so even if the space is changed
this flat surface
will eventually create infinite flat surfaces
But the process of making that
is the same as applying
this matrix we talked about earlier
It's the same
So ax+by, cx+dy
Applying this linear transformation is the same
This is how it's applied
On x, multiply (a, c)
Then on y, multiply (b, d)
and the results are the same
On an arbitrary point
we multiplied x on the first basis vector
and multiplied y on the second basis vector
Just like that, on a changed vector of (1, 0)
which is (a, c), we multiply x
We applied the same proportion
And on the changed vector of (0, 1), which is (b, d)
we apply y
and it proceeds the same way as the linear transformation from earlier
Then here, this value of the matrix
which we mentioned as corresponding to linear transformation
when we look at the column vector, not the row
there are two column vectors
This 2x2 matrix, corresponding to the function
can be seen as the column vector
Here, the first column vector is (a, c)
It stands for the changed value of
the first basis vector
And (b, d), corresponding to the second column
is the changed value of the second basis vector
Therefore, we're tracking the difference of this basis vector
That's what using a matrix is
Using this matrix designed as abcd
is actually looking at the column vector
and identifying the two standard basis vectors
that each change into (a, c) and (b, d)
in this process
When we think of it this way, then we can easily design
the transformation we want
For example, we'll take a look at the scale transformation matrix
Let's say there's this basic object in the original space
and I want to stretch this horizontally
We'll stretch it "a" times
And vertically, we'll shrink it "b" times
Then each basis vector turns out this way
(1, 0) increases to (a, 0)
and (0, 1) decreases to (0, b)
When this is expressed as a matrix
each of the changed basis vector, (a, 0) and (0, b)
just needs to be inserted as the column vector
Then it's made into a 2x2 matrix
that actually conducts the transformation
To actually try it out, when x, y vector is multiplied here
it becomes the matrix ax, by
Here, the x was multiplied by a, and y was multiplied by b
and it can be seen as a linear transformation
It corresponds to scale transformation
We'll now think of translation
I'll translate a space to the side like this
When we leave one side as-is, and push the other side
since x-axis is fixed, it stays as-is
Then the first basis vector has no change
Just use the (1, 0) as-is
When we slant it one unit to the side
the (0, 1) vector changes into (1, 1)
Then, we just insert (1, 1) into the second column
This is the translation of
pushing y-axis one unit toward the x-axis
If we pushed it "a" times
then just replace it with (a, 1)
and we'll end up with a matrix with the wanted amount of translation
That's how you can design the matrix
This time, we'll think about rotation, 90 degrees
clockwise
For rotation, we mentioned earlier but
the size of the two basis vectors are the same as the original
and it maintains 90 degrees, and the direction of the 90 degrees
also stay the same
This way, the shape of the object is maintained
Therefore, rotation keeps the shape of the object as-is
but changes the direction
When we rotate it 90 degrees clockwise
x-axis would to go negative y-axis, and y-axis would become x-axis
It would become like this
Then since the difference of x-axis is 0, -1
make this the first column
And put (1, 0) in the second column
Then you get a 90 degrees rotation
It becomes a rotation that rotates 90 degrees clockwise
If we actually multiply this
If we multiply the actual vectors, x and y
the result becomes x
When we multiply the matrix of x and y
the first element would become y
and the second element would become -x
So 90 degrees rotation means
flipping x and y
and putting a negative sign on the y value
Put the opposite sign on it
and it gets solved right away, actually
Even if we don't use a matrix
we can obtain it right away by swapping
This time, we'll learn about the
90 degrees counterclockwise rotation
As we've seen earlier, we can predict it right away
Counterclockwise means it's turning this way
That means the y-axis became -x
and the x-axis became the y-axis
So since y-axis became -x
and x-axis became the y-axis
it means a rotation of (0, 1), (-1, 0)
For this, it's the same
Swap the two
and put the opposite sign on the first element
Then you can calculate it right away
With that, we learned about the 90 degrees rotation
How would the rotation of an arbitrary value, theta, work?
For this, it's the same method as
when we used trigonometric functions last time
For each of the two standard basis vectors
When the first standard basis vector is rotated θ degrees
this moves to point (cosθ, sinθ)
And when (0, 1) is rotated θ degrees
the vector moves to (-sinθ, cosθ)
Then how would we make
the rotation matrix that corresponds to this?
Set (cosθ, sinθ) as the first column
and (-sinθ, cosθ) as the second column
This way, you can implement a rotation
on an arbitrary value of θ
When you make a matrix like this and try multiplying x and y
the result gives you xcosθ-ysinθ as the first element
and xsinθ+ycosθ as the second element
This is the same result as
the calculated value from trigonometric functions earlier
Therefore, from now on, if we're rotating a vector
with a value of θ
think of the coordinates of these two basis vectors
Since they're similar right triangles
the y value here becomes x value, the opposite way
and here, the x value becomes the y value
Therefore, you can see that the first (cosθ, sinθ)
becomes (-sinθ, cosθ) for the y value
As long as you clearly know these two vectors
you just need to insert them here one by one
cosθ, sinθ, -sinθ, cosθ
This becomes the rotation matrix
With that, we learned about the three basic transformations
that we'll need from now on
Those were, scaling, translation, and rotation
We learned about these three types
and how each of these
are expressed as matrix
Then finally, we're going to talk about
the multiplication of matrix
They say that matrix is simple but
we don't necessarily use matrices just because they're simple
There's a very important characteristic
that the matrix has
We can also call it the characteristic of matrix multiplication
Let's learn about it
Let's say that there are three vector spaces, like below
Let's say that each is real vector space R2
Then if we apply linear transformation twice
the vector space will be transformed twice
and it will ultimately proceed into a new vector space
We'll call the first transformation Matrix B
and we'll call the second transformation Matrix A
If we say that it will go through two transformations
and if we express this in an equation
multiply the element V, of the first vector space
with matrix B
then, you'll ultimately get the element of the second vector space
which is vector u
When you multiply vector u with matrix A
it proceeds to the last vector w
That is expressed in this equation
But for matrix, I've mentioned earlier that
the associative property stands
Therefore, we'll try calculating this equation after switching the order
Then w has the same result as
v multiplied to
the product of matrix A and B
Then let me explain what this is
Matrix of A and B multiplied is also a square matrix, after all
It's a 2x2 square matrix
What the square matrix itself means is
it serves the same role as a composite function
which goes directly from vector space V to vector space W
As mentioned earlier, a matrix is
a linear transformation, and transformation is morphism
and morphism is ultimately a function
Therefore, for the result of multiplying these two matrices
we can ultimately say that matrix corresponds to function
and this brings the same result
as the concept of composite function
that we learned earlier
Normally, when we learn about trigonometric functions
we learn a lot about the addition formula
and memorize them
cos(α+β) is CCSS, that's how I learned it
And the addition formula for the sine function is
SCCS, that's how I learned it
Rather than just memorizing it
we're going to actually act it out using matrix multiplication
Here, let's say that we first rotate it by α degrees
and then rotate it by β degrees
Rotating it by α degrees first
and then rotating it by β degrees
is obviously the same as
rotating it by α+β degrees
Then taking the result from α degree rotation
and the result from β degree rotation
and multiplying the two transformations
is the same as
rotating once by α+β degrees
Therefore, I wrote down the α degree rotation here
Multiplying these together is the same as what?
The same as applying α+β
Then here, we just need to take a look at the first column
Cos(α+β) is the same as
CCSS, thus (cos α·cos β)+(-sin α·sin β)
And for sin(α+β), we usually call it SCCS
(sin α·cos β) and then (cos α·sin β)
The order has changed, but since the associative property stands
we can call it SCCS
So it's the same as this, and I left this as a question mark but
the rest are actually the same as well
Ultimately, the second element here
The first and second elements of column 2 are all the same
This corresponds to -sin(α+β)
and this corresponds to cos(α+β)
So later, by any chance
if you can't remember the addition formula of trigonometric functions
use the rotation of trigonometric functions
then you'll be able to proceed right away
I hope you use it usefully
Finally, we'll talk about the advantages of
multiplication of matrices
As mentioned earlier, the associative property holds true for matrix
so the order doesn't matter
Doing this first, as long as the direction is the same
the order doesn't matter
Normally, the transformation is applied on the vector
and another transformation is applied on the new vector
and then another transformation on the new vector
That's how we should proceed
But after all, it's the same as
multiplying the transformation matrices first
and then multiplying
the original vector
From now on, when we
basically express something on the computer
we go through a lot of linear transformation processes
We go through at least these 5 processes
Scale, rotation, translation, view, and projection
are the five processes
It means there are five types of these
The transformation itself is A, B, C, D, and E
Rather than calling it A, B, C, D, E
we take the first letter of each word
S for scale, R for rotation
T for translation, and
V for view and P for projection
We'll basically have these five transformations
Let's say that we're expressing a character
and the character is composed of
100,000 dots
Then in order to show this character of 100,000 dots
on the screen, I need to go through these five matrices
Then basically, we'll need 500,000 calculations
As you can see here, we need 500,000 calculations
But the transformation itself is always the same
That means we don't need to calculate them separately
We'll multiply the matrices PVTRS
and make it beforehand
Once we create a matrix with the five transformations applied
then all we need to do is apply that matrix for 100,000 dots
and we will get the same result
Therefore, we can decrease 500,000 calculations
to 100,000 calculations
Because of these characteristics of a matrix
computer graphics
especially game graphics that are sensitive to sound
must use matrices
In all the base processes of computer graphic transformations
these formulas and equations of the matrix are used
as what you should know
Until now, we learned about the matrix, why we use the matrix
and the three types of transformation
that we'll often use, and their mechanisms
Inverse matrix
First, inverse matrix corresponds
to the concept of inverse function that we learned before
In the big perspective of linear transformation
matrix is ultimately a concept of function
Therefore, we can say that inverse matrix is also the same concept as an inverse function
Then there's a special function
that always came along with inverse function
That was the identity function
Identity function referred to a function where
the results of the domain and the range correspond to the same value
In the same way as this concept
the identity matrix exists for matrices as well
We'll now learn about how this is composed
An identity matrix ultimately means that
the original space and the transformed space after linear transformation
have the same values
That means, the two standard basis vectors that formed up the original space
have the same values even after transformation
Therefore, when designing an identity matrix
the first column of the first changed standard basis vector
uses the standard basis vector as-is
It uses (1, 0)
And for the second column, (0, 1) is used
to design the identity matrix
Then to see if the results of applying the identity matrix
really has no change
we'll name an arbitrary matrix abcd
When we multiply this identity matrix
we can see that the result value is the same
When we multiply any vector to an identity matrix
an identical vector is made
Therefore, with this special identity matrix
we can add a concept of inverse matrix
It takes the result of a linear transformation, transformed by matrix
and turns it back to the original
It's a linear transformation
that turns back a linear-transformed result
Therefore, when we combine these two, it becomes an identity transformation
Since it created the same value as the original, it is an identity transformation
If you see here, (1, 0) and (0, 1)
of this standard basis vector of the original space
was changed into ac and bd
In order to turn this back to its original
so for the transformation to turn back into A
it is conceptually settled that an inverse matrix of A exists
And the result of combining these two
comes back to the original
Therefore, in the concept of a function, it comes back to identity function
In the concept of matrix, combining inverse matrix and the matrix
becomes the identity matrix
Then how can we calculate this inverse matrix?
It's good to know about the concept of a determinant beforehand
A determinant is
a property of a matrix
Let's say we have a two dimensional square matrix
called abcd
the determinant, which is the property of this matrix
is obtained through the calculation ad-bc
We'll learn about what ad-bc means
Under here, I wrote down
a system of equations
If we say that this system of equations is abcd
and set the x, y, coefficients of 2, 1, 1, 0.5
as abcd, and then when we do 2x0.5 - 1x1
we can see that it becomes 0
I'll explain what happens when the value of ad-bc
becomes 0 like this
If you look here, when we multiply the second equation by 2
it becomes 2x+y=8
Then this system of equations has no solution
This condition of having no solutions
is distinguished through this equation of a determinant
That's why it's called a determinant
It's a value that can analyze and determine something
When we express this system of equations as a matrix
it can be expressed like this
We can use these coefficients
and make it into a matrix like this
In this matrix too, ad-bc would give us 0
Then we'll see what kind of a transformation
this matrix forms
In this matrix, the first standard basis vector transformed to (2, 1)
and the second standard basis vector (0, 1)
has been transformed into (1, 0.5)
When the second vector is multiplied by 2
we get (2, 1)
therefore, they have the same slope
That means, the two vectors (1, 0) and (0, 1)
that were linearly independent
ended up with same slopes through the linear transformation process
and changed into a linearly dependent relationship
The following expresses this as a picture
The vectors with different slopes like this
changed into a space having the same slope
Then here, we were able to create all dots
of the two dimensional space through a linear combination
but here, even when we combine the two vectors
we can only create the dots
on top of this slope
Therefore, a 2D space has been changed into a one-dimensional space
A bad transformation, we could say
Therefore, when this transformation is applied
the result of the linear transformation brought down 2D into 1D
so ultimately, there's no path back
from one-dimension to two-dimension
This means
we cannot make the inverse matrix
Therefore, before obtaining the inverse matrix
we must know the determinant first because
the inverse matrix may or may not exist
How do we determine that?
Use the determinant ad-bc
to first determine whether the inverse matrix exists
or doesn't exist
Then how come the dimension disappears
when the value of ad-bc is 0?
Let's check the area of the parallelogram formed by the two vectors
First, the square formed by the two standard basis vectors
in the original space had an area of 1
But when e1 is transformed into (a, c)
and when e2 is transformed into (b, d)
a parallelogram like this is formed
When we try obtaining the final value here
with the x value of a+b
and y value of c+d, we multiply them to obtain a rectangular area
When we obtain this gray area
by subtracting these triangle and rectangle areas
we get the value ad-bc
That means, ad-bc
is the area of the parallelogram
formed by two linearly independent vectors
as they go through linear transformation
The fact that this is 0, means the area of the parallelogram is 0
Therefore, that means the two vectors
are along the same straight line
With that, we learned about the meaning of a determinant
Then let's say that the value of the determinant is not 0
Then how can we use that?
First of all, the value of ad-bc
is ultimately going from the area of 1, formed by the two standard vectors
to the parallelogram of the form ad-bc
The changed area
the size has been changed by ad-bc
Then how do we turn it back?
We can restore it by multiplying the inverse of the changed size
So the determinant
can simply determine whether there's an inverse matrix
but it can also be used when the space has been changed
to tell how much size change has occurred
after a transformation
Now that we can obtain this inverse matrix
I'll briefly talk about how we can utilize it
Normally, it's useful for
obtaining the solution of a system of equations that we've seen earlier
For obtaining the solution as well
we showed this visually because we use graphics
but like this, we can use matrices very usefully
to obtain the solution
Let's say that this matrix is A, and (x, y) is v
and let's say that the result value is v'
We would get an equation like this
Here, we know v', the result
We know the result and
we also know what transformation we're applying
But let's say that we don't know
what the original value is
Then this is how we solve this
If we obtain the inverse matrix of A and multiply it to both sides
we would do A^-1 times A
and here, we would multiply the transformed v' to A^-1
Then for this value
since the associative property stands here
this eventually becomes the identity matrix I, and we would be left with v
Therefore, if we can obtain the inverse matrix
multiply the inverse matrix on the transformed vector
and we would be able to find the solution
of the original value right away
Just like that, matrix can be useful
for solving equations
It can be used for various, complex problems
Just now, we used it for a very simple form of
system of equations with just two equations
but even with 10 equations or
10 complex coefficients tied together
as long as we know the principle of the matrix
and as long as we have enough samples for each
we can ultimately find the solution
We can use the Gaussian elimination
and the Cramer's rule to obtain the inverse matrix
For the main transformations that we use for graphics
although they would be good to know, you don't really need to know these
That's because we can obtain the inverse matrix intuitively
We'll first look at the scale matrix among the matrices
We'll think about how the inverse matrix
of a scale matrix works
There's a matrix where e1 was increased by a times
and e2 was decreased by b times, from a standard basis vector
In order to make that matrix
come back to (1, 0) and (0, 1)
what should we do?
It's so simple, we just need to decrease by the amount we increased
So if we multiply the inverse of the increased coefficient
it comes back to (1, 0) and (0, 1)
If we multiply the inverse of the increased amount
and make it into a scale matrix
we can say that this becomes the inverse matrix of the scale matrix
that comes back to the original size
We'll also take a look at translation matrix
We translated it
If we only translate on one side, this part increases by a times
Then do should we make it come back to the original?
We would just translate to the opposite direction
Since we just need to push to the opposite side
it would come back to the original if we translate by -a
Therefore, for the inverse matrix of a translation matrix translated by "a"
translating it by "-a" allows us to easily design the inverse matrix
Next, I'll talk about the inverse matrix of a rotation matrix
The first standard basis vector is (cos, sinθ)
and the second standard basis vector is (-sinθ, cosθ)
How can we change this back to the original?
The way of turning it back to its original
is rotating it in the opposite direction by the same amount
In other words, rotating it -θ degrees
If this is a normal rotation
we would substitute -θ degrees into the rotation
Then based on the property of a cos function
where the cos function symmetrical
about the y-axis
-cosθ and cosθ have the same values
Therefore, we can see that the diagonal elements are the same
In the case of a sin function, it's symmetrical
but the sign changes vertically
Therefore, obtaining -sinθ
is the same as sin(-θ)
Ultimately, this goes from negative to positive
and the positive becomes a negative
in this matrix
This is the inverse matrix of a rotation
which turns a rotation matrix back to its original
If we closely examine R_θ and R_(-θ) here
what relationship would they have?
First of all, the value of cosθ is the same
and we can see that only the sinθ values have switched
Therefore, this can also be seen as a transpose relationship
To organize it, a rotation matrix and its inverse matrix
have a transpose relationship with each other
And the inverse matrix of a rotation matrix
is rotation toward the opposite direction
as what we can get from this
With that, we learned about the essential inverse matrices
needed for graphics that we'll perform later
That's all for this lecture
Great job for listening to this lesson
Thank you
Matrix Matrix Numbers arranged inside a rectangle as rows and columns Basic operations of matrix: addition of matrices, multiplication of a matrix...
Characteristics of matrix multiplication Doesn't satisfy the commutative property Satisfies the associative property Satisfies (A·B)^T=B^T·A^T Tran...
Linear transformation and matrix Square matrix is linear transformation where the same dimensional space correspond to each other Column major...
Visualization of linear transformation Linear transformation of the original vector space: [a b] [c d] Using a matrix means tracking the change of...
Scale transformation matrix: [a 0] [0 b] Translation matrix: [1 a] [0 1]
90 degrees clockwise rotation matrix: [ 0 1] [-1 0] 90 degrees counterclockwise rotation matrix: [0 -1] [1 0]
Rotation matrix of an arbitrary θ: [xcosθ - ysinθ] [xsinθ + ycosθ]
Multiplication of matrix Associative property stands Product of square matrix has the same result as composite function
Product of matrix can be used for the addition formula of trigonometric function Matrix operation with a valid associative property guarantees the...
Major linear transformation: Scale(S), Rotation(R), Translation(T), View(V), Projection(P)
When 5 linear transformations are the same, the product of PVTRS can be applied to lessen the number of operations
Inverse matrix Inverse matrix Identity matrix: Matrix with no change in the linear transformation I = [1 0] [0 1]
Inverse matrix: Linear transformation that reverts the linearly transformed result Combining inverse matrix and matrix results in identity matrix H...
Determinant: Expression that determines a condition with no solution A = [a b] [c d], det(A) = ad - bc
Using determinant ad-bc to determine whether the inverse matrix exists Utilizing inverse matrix: useful for solving a system of equations
Inverse matrix of scale matrix: [1/a 0] [0 1/b] Inverse matrix of translation matrix: [1 -a] [0 1]
Inverse matrix of rotation: [ cos(θ) sin(θ)] [-sin(θ) cos(θ)]