Introduction to Matrix Multiplication Through Affine Transformations

advertisement
Introduction to Matrix Multiplication Through Affine Transformations
Ad Astra Education
By Dov Kruger PhD
Matrices are rather abstract. People see matrix multiplication and don't understand what it means. So
let's look at some examples that have geometric application, and incidentally power all those high
powered graphics cards we like to play 3-D video games on.
I'm going to use Matlab or Octave notation here because I can run commands in Octave and paste them
and results right in here. Let me know if you have any problems understanding.
Notation:
A row vector is written:
x = [1 2 3]
Octave then responds:
x =
1
2
3
A column vector is written:
y = [1;2;3]
Octave replies with:
y =
1
2
3
A matrix can be entered in octave with a semicolon at the end of each row:
octave:11> A = [1 0 0;0 1 0 ; 0 0 1]
A =
1
0
0
0
1
0
0
0
1
For 2-D, let's make it even simpler and go to a 2x2 matrix:
octave:12> A = [1 0;0 1]
A =
1
0
0
1
Suppose you have a point at (3, 1). If you multiply matrix A by this point, nothing happens:
octave:13> x=[3;1]
x =
3
1
octave:14> A*x
ans =
3
1
That's because the matrix multiplication stands for the following:
1 0
𝑎 𝑏
𝐴=[
]=[
]
0 1
𝑐 𝑑
𝑥 ′ = 𝑎𝑥 + 𝑏𝑦 = 1𝑥 + 0𝑦 = 𝑥
𝑦′ = 𝑐𝑥 + 𝑑𝑦 = 0𝑥 + 1𝑦 = 𝑦
In other words, x' and y', the changed values of x and y, are not changed at all because A is the identity
matrix, the matrix which when you multiply something by it, keeps its values. Can you think of the
analogy in regular scalar numbers? What, number, multiplied by anything, gives the same number?
Suppose you want to stretch the point out. Make it twice as big in the x and y:
octave:15> A = [2 0 ; 0 2]
A =
2
0
0
2
octave:16> A*x
ans =
6
2
With twos down the main diagonal, this matrix doubles it.
So how does this work in graphics on a computer? Well, suppose you are drawing a shape on a screen,
like a square. It has four coordinates:
3,9
10,9
3, 2
10, 2
If you apply A*x to each point in the square, the entire square will double in size. Why? Because each
point gets twice as far away from the origin. Try it on graph paper!
There are a few more tricks you can pull, but they require a bit more advanced math. If you don't know
trigonometry yet, just take on faith that for any angle , you can compute two functions:
sin(), cos()
For  = 45°
√2
sin() = cos() = ≅ .707
2
If you make your matrix:
𝑐𝑜𝑠𝜃 𝑠𝑖𝑛𝜃
. 707 . 707
𝐴=[
]=[
]
−.707 . 707
−𝑠𝑖𝑛𝜃 𝑐𝑜𝑠𝜃
And draw a graph showing the original point and the new point as vectors, you can see that the point
has been rotated by 45 degrees clockwise.
quiver(0,0,x(1),x(2))
hold on
x2 = A*x
quiver(0,0,x2(1), x2(2))
x3 = A*x2
quiver(0,0,x3(1), x3(2))
axis equal
So what do you think would happen if you applied this operation to four corners of a rectangle, and then
drew the rectangle?
Download