There are three kind of basic linear transformation, we call this affine transformation.
Translation
For every vertex coordinate of shape S, point p(x,y,z) apply a transition and
get point p(x′,y′,z′)
So we have
Equation 1.0
x′=x+Txy′=y+Tyz′=z+Tz
In this case Tz is 0, very intuitive!
Rotation
First, let’s assume we are rotating around z-axis. Pick any point p. point p
move to point p′ after the rotation.
We have
Equation 1.1
y=rsinα
Similarly
x′=rcos(α+β)y′=rsin(α+β)
Use the addition theorem of trigonometric functions
x′=r(cosαcosβ−sinαsinβ)y′=r(sinαcosβ+cosαsinβ)
By assigning Equation 1.1, you get the following expressions
Equation 1.2
x′=xcosβ−ysinβy′=xsinβ+ycosβz=z′
Scaling
Clearly, We have
Equation 1.3
x′=Sx×xy′=Sy×yz=Sz×z
Matrices
You will find it time consuming to write a mathematical expression every time
you need a new set of transformation. To solve this problem, we introduce a
new tool: Matrix.
Rotation Matrix
First, there is transformation
x′y′z′=adgbehcfi×xyz
For now, you just hard code how matrix multiplication works, you could learn linear algebra later.
x′=ax+by+czy′=dx+ey+fzz′=gx+hy+iz
comparing with Equation 1.2, we know that a=cosβ, b=−sinβ and c=0. Also,
d=sinβ, e=cosβf=0g=0h=0i=1, then we have matrix
x′y′z′=cosβsinβ0−sinβcosβ0001×xyz
We call this a transformation matrix
Translation Matrix
What about translation? You can’t product x=x+Tx by 3x3 matrix. Again, yuo have to hard code the resolution.
the answer is to use to 4x4 matrix called Homogeneous Transformation Matrix
x′y′z′1=100001000010TxTyTx1×xyz1
You might wonder why there are four coordinates for p(x,y,z), this is called Homogeneous coordinates and you can ignore it.
Scaling Matrix
We can get a scaling matrix:
x′y′z′1=Sx0000Sy0000Sz00001×xyz1
modelMatrix
Say we want to do a translation T, then rotation R followed by scaling S. First we make a translation matrix multiply origin Matrix A
step1:
T⋅A
step2:
R⋅T⋅A
step3:
S⋅R⋅T⋅A
An important thing you need to know is that
S⋅R⋅A=R⋅S⋅A(S⋅R)⋅T⋅A=S⋅(R⋅T)⋅A
means that matrix multiplication is associative but not commutative. We call this kind of matrix M=S⋅R⋅T modelMatrix