(个人笔记,由于刚开始学习再加上英语不太好,所以有的地理解的可能不太对,望指正)
Chapter 6 Transformation Matrices
6.1 2D Linear Transformation
6.1.1 Scaling
s c a l e ( s x , s y ) = [ s x 0 0 s y ]
scale(s_x, s_y) = \begin{bmatrix}
s_x & 0 \\ 0 & s_y
\end{bmatrix}
s c a l e ( s x , s y ) = [ s x 0 0 s y ]
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 ]
shearX(s) = \begin{bmatrix}
1 & s \\ 0 & 1
\end{bmatrix} \\
shearY(s) = \begin{bmatrix}
1 & 0 \\ s & 1
\end{bmatrix}
s h e a r X ( s ) = [ 1 0 s 1 ] s h e a r Y ( s ) = [ 1 s 0 1 ]
shear操作可以看作是只沿一个方向进行旋转
6.1.3 Rotation
r o t a t e ( ϕ ) = [ c o s ϕ − s i n ϕ s i n ϕ c o s ϕ ]
rotate(\phi)=\begin{bmatrix}
cos\phi & -sin\phi \\
sin\phi & cos\phi
\end{bmatrix}
r o t a t e ( ϕ ) = [ c o s ϕ s i n ϕ − s i n ϕ c o s ϕ ]
计算过程:
r = x a 2 + y a 2 x a = r c o s α y a = r s i n α x b = r c o s ( α + ϕ ) = r c o s α c o s ϕ − r s i n α s i n ϕ y b = r s i n ( α + ϕ ) = r s i n α c o s ϕ + r c o s α s i n ϕ
r = \sqrt{x_a^2 + y_a^2} \\
x_a = r cos\alpha \\
y_a = r sin \alpha \\
x_b = r cos(\alpha + \phi) = rcos\alpha cos\phi - rsin\alpha sin\phi \\
y_b = r sin(\alpha + \phi) = rsin\alpha cos\phi + rcos\alpha sin\phi
r = x a 2 + y a 2 x a = r c o s α y a = r s i n α x b = r c o s ( α + ϕ ) = r c o s α c o s ϕ − r s i n α s i n ϕ y b = r s i n ( α + ϕ ) = r s i n α c o s ϕ + r c o s α s i n ϕ
如图所示:
旋转矩阵是正交矩阵
6.1.4 Reflection
r e f l e c t Y = [ − 1 0 0 1 ] r e f l e c t X = [ 1 0 0 − 1 ]
reflectY = \begin{bmatrix}
-1 & 0 \\ 0 & 1
\end{bmatrix} \\
reflectX = \begin{bmatrix}
1 & 0 \\ 0 & -1
\end{bmatrix}
r e f l e c t Y = [ − 1 0 0 1 ] r e f l e c t X = [ 1 0 0 − 1 ]
6.1.5 Composition and Decomposition of Transformations
6.1.6 Decoposition of Transformations
Symmetric Eigenvalue Decomposition
对于对称矩阵来说,可以进行以下分解过程:
A = R S R T
A = RSR^{T}
A = R S R T
R表示旋转,S表示缩放。
Singular Value Decomposition
对于非对称矩阵来说,可以使用奇异值分解。
A = U S V T
A = USV^{T}
A = U S V T
对于奇异值分解来说UV可能不表示旋转,也可能表示反射,可以通过行列式的值判断:+1表示旋转,-1表示反射。
Paeth Decomposition of Rotations
使用shear操作代替旋转操作
[ c o s ϕ − s i n ϕ s i n ϕ c o s ϕ ] = [ 1 c o s ϕ − 1 s i n ϕ 0 1 ] [ 1 0 s i n ϕ 1 ] [ 1 c o s ϕ − 1 s i n ϕ 0 1 ]
\begin{bmatrix}
cos\phi & -sin\phi \\
sin\phi & cos\phi
\end{bmatrix}=\begin{bmatrix}
1 & \frac{cos\phi-1}{sin\phi} \\
0 & 1
\end{bmatrix}\begin{bmatrix}
1 & 0 \\
sin\phi & 1
\end{bmatrix}\begin{bmatrix}
1 & \frac{cos\phi-1}{sin\phi} \\
0 & 1
\end{bmatrix}
[ c o s ϕ s i n ϕ − s i n ϕ c o s ϕ ] = [ 1 0 s i n ϕ c o s ϕ − 1 1 ] [ 1 s i n ϕ 0 1 ] [ 1 0 s i n ϕ c o s ϕ − 1 1 ]
该转化对于raster rotation非常有效,因为对于raster operation来说,shear操作是很高效的。
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}
s c a l e ( s x , s y , s z ) = ⎣ ⎡ s x 0 0 0 s y 0 0 0 s z ⎦ ⎤
旋转
r o t a t e Z ( ϕ ) = [ c o s ϕ − s i n ϕ 0 s i n ϕ c o s ϕ 0 0 0 1 ] r o t a t e X ( ϕ ) = [ 1 0 c o s ϕ − s i n ϕ 0 s i n ϕ c o s ϕ 0 ] r o t a t e Y ( ϕ ) = [ c o s ϕ 0 s i n ϕ 0 1 0 − s i n ϕ 0 c o s ϕ ]
rotateZ(\phi)=\begin{bmatrix}
cos\phi & -sin\phi & 0 \\
sin\phi & cos\phi & 0 \\
0 & 0 & 1
\end{bmatrix} \\
rotateX(\phi)=\begin{bmatrix}
1 & 0 & \\
cos\phi & -sin\phi & 0 \\
sin\phi & cos\phi & 0
\end{bmatrix} \\
rotateY(\phi)=\begin{bmatrix}
cos\phi & 0 & sin\phi \\
0 & 1 & 0 \\
-sin\phi & 0 & cos\phi
\end{bmatrix}
r o t a t e Z ( ϕ ) = ⎣ ⎡ c o s ϕ s i n ϕ 0 − s i n ϕ c o s ϕ 0 0 0 1 ⎦ ⎤ r o t a t e X ( ϕ ) = ⎣ ⎡ 1 c o s ϕ s i n ϕ 0 − s i n ϕ c o s ϕ 0 0 ⎦ ⎤ r o t a t e Y ( ϕ ) = ⎣ ⎡ c o s ϕ 0 − s i n ϕ 0 1 0 s i n ϕ 0 c o s ϕ ⎦ ⎤
shear
s h e a r X ( d y , d z ) = [ 1 d y d z 0 1 0 0 0 1 ]
shearX(d_y, d_z) = \begin{bmatrix}
1 & d_y & d_z \\
0 & 1 & 0 \\
0 & 0 & 1
\end{bmatrix}
s h e a r X ( d y , d z ) = ⎣ ⎡ 1 0 0 d y 1 0 d z 0 1 ⎦ ⎤
6.2.1 Arbitrary 3D Rotation
绕任意向量旋转,可以首先将以该向量建立一个基,从该坐标系转换到标准坐标系,利用绕坐标轴旋转完成之后,再利用旋转矩阵的逆矩阵转回来:
[ x u x v x w y u y v y w z u z v z w ] [ c o s ϕ − s i n ϕ 0 s i n ϕ c o s ϕ 0 0 0 1 ] [ x u y u z u x v y v z v x w y w 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\phi & -sin\phi & 0 \\
sin\phi & cos\phi & 0 \\
0 & 0 & 1
\end{bmatrix}\begin{bmatrix}
x_u & y_u & z_u \\
x_v & y_v & z_v \\
x_w & y_w & z_w
\end{bmatrix}
⎣ ⎡ x u y u z u x v y v z v x w y w z w ⎦ ⎤ ⎣ ⎡ c o s ϕ s i n ϕ 0 − s i n ϕ c o s ϕ 0 0 0 1 ⎦ ⎤ ⎣ ⎡ x u x v x w y u y v y w z u z v z w ⎦ ⎤
If we have a rotation matrix and we wish to have the rotation in axis-angle form, we can compute the one real eigenvalue (which will be λ = 1), and the corresponding eigenvector is the axis of rotation. This is the one axis that is not changed by the rotation.
6.2.2 Transforming Normal Vectors
法线向量的变换不能直接用顶点转换矩阵M进行转换
设法线为n,切线为t,法线转化矩阵为N。
首先有
n T t = 0
n^{T}t = 0
n T t = 0
那么经过转换之后法线和切线也仍然垂直,所以有
n N T t M = 0 ( 6 − 1 )
n^{T}_Nt_M = 0 \ \ \ (6-1)
n N T t M = 0 ( 6 − 1 )
推导
n T t = n T I t = n T M − 1 M t = 0 ( n T M − 1 ) t M = 0
n^Tt=n^TIt=n^TM^{-1}Mt=0 \\
(n^TM^{-1})t_M=0\\
n T t = n T I t = n T M − 1 M t = 0 ( n T M − 1 ) t M = 0
根据6-1,可得
n N T = n T M − 1 n N = ( n T M − 1 ) T = ( M − 1 ) T n
n^{T}_N = n^TM^{-1} \\
n_N = (n^TM^{-1})^{T} = (M^{-1})^{T}n
n N T = n T M − 1 n N = ( n T M − 1 ) T = ( M − 1 ) T n
所以法线转换矩阵为( M − 1 ) T (M^{-1})^{T} ( M − 1 ) T
6.3 Translation and Affine Transformations