6. Transformation Matrices
6.1 2D Linear Transformations
6.1.1 Scaling
s c a l e s ( s x , s y ) = [ s x 0 0 s y ] scales(s_x,s_y)= \begin{bmatrix} s_x & 0 \\ 0 & s_y \end{bmatrix} scales(sx,sy)=[sx00sy]
6.1.2 Shearing
s h e a r _ x ( s ) = [ 1 s 0 1 ] , s h e a r _ y ( s ) = [ 1 0 s 1 ] shear\_x(s)= \begin{bmatrix} 1 & s \\ 0 & 1 \end{bmatrix}, shear\_y(s)= \begin{bmatrix} 1 & 0 \\ s & 1 \end{bmatrix} shear_x(s)=[10s1],shear_y(s)=[1s01]
6.1.3 Rotation
r
o
t
a
t
e
(
θ
)
=
[
cos
θ
−
sin
θ
sin
θ
cos
θ
]
rotate(\theta)= \begin{bmatrix} \cos \theta & -\sin \theta \\ \sin \theta & \cos \theta \end{bmatrix}
rotate(θ)=[cosθsinθ−sinθcosθ]
6.1.4 Reflection
r e f l e c t _ y ( s ) = [ − 1 0 0 1 ] , r e f l e c t _ x ( s ) = [ 1 0 0 − 1 ] reflect\_y(s)= \begin{bmatrix} -1 & 0\\ 0 & 1 \end{bmatrix}, reflect\_x(s)= \begin{bmatrix} 1 & 0 \\ 0 & -1 \end{bmatrix} reflect_y(s)=[−1001],reflect_x(s)=[100−1]
6.1.5 Composition and Decomposition of Transformations
6.1.6 Decomposition of Transformations
-
Symmetric Eigenvalue Decomposition
A = R S R T A=RSR^T A=RSRT
for example:
[ 2 1 1 1 ] = R [ λ 1 0 0 λ 2 ] R T = r o t a t e ( 31. 7 ∘ ) s c a l e ( 2.618 , 0.382 ) r o t a t e ( − 31. 7 ∘ ) \begin{aligned} \begin{bmatrix} 2 & 1 \\ 1 & 1 \end{bmatrix}=&R\begin{bmatrix} \lambda_1 & 0\\ 0&\lambda_2 \end{bmatrix}R^T\\ =&rotate(31.7^\circ)scale(2.618, 0.382)rotate(-31.7^\circ) \end{aligned} [2111]==R[λ100λ2]RTrotate(31.7∘)scale(2.618,0.382)rotate(−31.7∘) -
Singular Value Decomposition
A = U S V T A=USV^T A=USVT
for example:
[ 1 1 0 1 ] = R 2 [ σ 1 0 0 σ 2 ] R 1 T = r o t a t e ( 31. 7 ∘ ) s c a l e ( 1.618 , 0.618 ) r o t a t e ( − 58. 3 ∘ ) \begin{aligned} \begin{bmatrix} 1 & 1 \\ 0 & 1 \end{bmatrix}=&R_2\begin{bmatrix} \sigma_1 & 0\\ 0&\sigma_2 \end{bmatrix}R_1^T\\ =&rotate(31.7^\circ)scale(1.618, 0.618)rotate(-58.3^\circ) \end{aligned} [1011]==R2[σ100σ2]R1Trotate(31.7∘)scale(1.618,0.618)rotate(−58.3∘) -
Paeth Decomposition of Rotations
[ cos θ − sin θ sin θ cos θ ] = [ 1 cos θ − 1 sin θ 0 1 ] [ 1 0 sin θ 1 ] [ 1 cos θ − 1 sin θ 0 1 ] \begin{bmatrix} \cos \theta&-\sin \theta\\ \sin \theta&\cos \theta \end{bmatrix}= \begin{bmatrix} 1&\frac{\cos \theta - 1}{\sin \theta}\\ 0&1 \end{bmatrix} \begin{bmatrix} 1&0\\ \sin \theta&1 \end{bmatrix} \begin{bmatrix} 1&\frac{\cos \theta - 1}{\sin \theta}\\ 0&1 \end{bmatrix} [cosθsinθ−sinθcosθ]=[10sinθcosθ−11][1sinθ01][10sinθcosθ−11]
This particular transform is useful for raster rotation because shearing is a very efficient raster operation for images; it introduces some jagginess, but will leave no holes.
6.2 3D Linear Transformations
s
c
a
l
e
(
s
x
,
s
y
,
s
z
)
=
[
s
x
0
0
0
s
y
0
0
0
s
z
]
scale(s_x,s_y,s_z)= \begin{bmatrix} s_x&0&0\\ 0&s_y&0\\ 0&0&s_z \end{bmatrix}
scale(sx,sy,sz)=⎣⎡sx000sy000sz⎦⎤
r
o
t
a
t
e
_
z
(
θ
)
=
[
cos
θ
−
sin
θ
0
sin
θ
cos
θ
0
0
0
1
]
rotate\_z(\theta)= \begin{bmatrix} \cos \theta & -\sin \theta&0 \\ \sin \theta & \cos \theta&0\\ 0&0&1 \end{bmatrix}
rotate_z(θ)=⎣⎡cosθsinθ0−sinθcosθ0001⎦⎤
r
o
t
a
t
e
_
x
(
θ
)
=
[
1
0
0
0
cos
θ
−
sin
θ
0
sin
θ
cos
θ
]
rotate\_x(\theta)= \begin{bmatrix} 1&0&0\\ 0&\cos \theta & -\sin \theta \\ 0&\sin \theta&\cos \theta\\ \end{bmatrix}
rotate_x(θ)=⎣⎡1000cosθsinθ0−sinθcosθ⎦⎤
r
o
t
a
t
e
_
y
(
θ
)
=
[
cos
θ
0
sin
θ
0
1
0
−
sin
θ
0
cos
θ
]
rotate\_y(\theta)= \begin{bmatrix} \cos \theta & 0&\sin \theta \\ 0&1&0\\ -\sin \theta&0&\cos \theta\\ \end{bmatrix}
rotate_y(θ)=⎣⎡cosθ0−sinθ010sinθ0cosθ⎦⎤
6.2.1 Arbitrary 3D Rotations
In matrix form, to rotate about the w-axis by an angle θ \theta θ:
[ x u x v x w y u y v y w z u z v z w ] [ cos θ − sin θ 0 sin θ cos θ 0 0 0 1 ] [ x u y v z w x u y v z w x u y v z w ] \begin{bmatrix} x_u&x_v&x_w\\ y_u&y_v&y_w\\ z_u&z_v&z_w \end{bmatrix} \begin{bmatrix} \cos \theta&-\sin \theta&0\\ \sin \theta& \cos \theta&0\\ 0&0&1 \end{bmatrix} \begin{bmatrix} x_u&y_v&z_w\\ x_u&y_v&z_w\\ x_u&y_v&z_w \end{bmatrix} ⎣⎡xuyuzuxvyvzvxwywzw⎦⎤⎣⎡cosθsinθ0−sinθcosθ0001⎦⎤⎣⎡xuxuxuyvyvyvzwzwzw⎦⎤
6.2.2 Transforming Normal Vectors
n
T
t
=
0
n^Tt=0
nTt=0
If we denote the desired transformed vectors as
t
M
=
M
t
t_M = Mt
tM=Mt and
n
N
=
N
n
n_N = Nn
nN=Nn,our goal is to find
N
N
N such that
n
N
T
t
M
=
0
n^T_Nt_M= 0
nNTtM=0
n
T
t
=
n
T
I
t
=
n
T
M
−
1
M
t
=
0
(
n
T
M
−
1
)
(
M
t
)
=
(
n
T
M
−
1
)
t
M
=
0
⇒
n
N
T
=
n
T
M
−
1
⇒
n
N
=
(
n
T
M
−
1
)
T
=
(
M
−
1
)
T
n
n^Tt=n^TIt=n^TM^{-1}Mt=0\\ (n^TM^{-1})(Mt)=(n^TM^{-1})t_M=0\\ \Rightarrow n^T_N=n^TM^{-1}\\ \Rightarrow n_N=(n^TM^{-1})^T=(M^{-1})^Tn
nTt=nTIt=nTM−1Mt=0(nTM−1)(Mt)=(nTM−1)tM=0⇒nNT=nTM−1⇒nN=(nTM−1)T=(M−1)Tn
6.3 Translation and Affine Transformation
In particular, homogeneous coordinates underlie the Homogeneous coordinates design and operation of renderers implemented in graphics hardware.
6.4 Inverses of Transformation Matrices
for example in 3D we have
M
=
R
1
s
c
a
l
e
(
σ
1
,
σ
2
,
σ
3
)
R
2
,
M
−
1
=
R
2
T
s
c
a
l
e
(
1
σ
1
,
1
σ
2
,
1
σ
3
)
R
1
T
M=R_1scale(\sigma_1,\sigma_2,\sigma_3)R_2,\\ M^{-1}=R_2^Tscale(\frac1\sigma_1,\frac1\sigma_2,\frac1\sigma_3)R_1^T
M=R1scale(σ1,σ2,σ3)R2,M−1=R2Tscale(σ11,σ12,σ13)R1T
6.5 Coordinate Transformations
P x y = [ u v e 0 0 1 ] P u v P_{xy}= \begin{bmatrix} u&v&e\\ 0&0&1 \end{bmatrix} P_{uv} Pxy=[u0v0e1]Puv