序
正文
modeling transformation 模型变换
viewing transformation 视图变换
scale transform
对于平面等比缩放:
[
x
′
y
′
]
=
[
s
0
0
s
]
[
x
y
]
\begin{bmatrix}x' \\y'\\\end{bmatrix} = \begin{bmatrix}s & 0 \\ 0 & s \\\end{bmatrix} \begin{bmatrix} x \\ y \\\end{bmatrix}
[x′y′]=[s00s][xy]
对于平面非等比缩放:
[
x
′
y
′
]
=
[
s
x
0
0
s
y
]
[
x
y
]
\begin{bmatrix}x' \\y'\\\end{bmatrix} = \begin{bmatrix}s_x & 0 \\ 0 & s_y \\\end{bmatrix} \begin{bmatrix} x \\ y \\\end{bmatrix}
[x′y′]=[sx00sy][xy]
切变(Shear Matrix):
[
x
′
y
′
]
=
[
1
a
0
1
]
[
x
y
]
\begin{bmatrix}x' \\y'\\\end{bmatrix} = \begin{bmatrix}1 & a \\ 0 & 1 \\\end{bmatrix} \begin{bmatrix} x \\ y \\\end{bmatrix}
[x′y′]=[10a1][xy]
旋转(绕原点,逆时针)(Rotation Matrix):
旋转矩阵:
R
θ
=
[
c
o
s
θ
−
s
i
n
θ
s
i
n
θ
c
o
s
θ
]
R_\theta = \begin{bmatrix}cos\theta & -sin\theta \\ sin\theta & cos\theta\\\end{bmatrix}
Rθ=[cosθsinθ−sinθcosθ]
R
−
θ
=
[
c
o
s
θ
s
i
n
θ
−
s
i
n
θ
c
o
s
θ
]
=
R
T
=
R
θ
−
1
R_{-\theta} = \begin{bmatrix}cos\theta & sin\theta \\ -sin\theta & cos\theta\\\end{bmatrix} =R^T=R_{\theta}^{-1}
R−θ=[cosθ−sinθsinθcosθ]=RT=Rθ−1
线性变换都可以写成
[
x
′
y
′
]
=
[
a
b
c
d
]
[
x
y
]
\begin{bmatrix}x' \\y'\\\end{bmatrix} = \begin{bmatrix}a & b \\ c & d \\\end{bmatrix} \begin{bmatrix} x \\ y \\\end{bmatrix}
[x′y′]=[acbd][xy]
平移变换通过矩阵只能写成
[
x
′
y
′
]
=
[
a
b
c
d
]
[
x
y
]
+
[
t
x
t
y
]
\begin{bmatrix}x' \\y'\\\end{bmatrix} = \begin{bmatrix}a & b \\ c & d \\\end{bmatrix} \begin{bmatrix} x \\ y \\\end{bmatrix} + \begin{bmatrix}t_x\\t_y\\\end{bmatrix}
[x′y′]=[acbd][xy]+[txty]
齐次坐标
对于2D的点,写成
(
x
,
y
,
1
)
T
(x,y,1)^T
(x,y,1)T,对于2D向量,写成
(
x
,
y
,
0
)
T
(x,y,0)^T
(x,y,0)T
通过其次坐标,可以将平移操作写成
(
x
′
y
′
w
′
)
=
(
1
0
t
x
0
1
t
y
0
0
1
)
⋅
(
x
y
1
)
=
(
x
+
t
x
y
+
t
y
1
)
\begin{pmatrix}x' \\y'\\ w'\\ \end{pmatrix} = \begin{pmatrix}1 & 0 &t_x \\ 0 & 1 &t_y \\ 0 & 0 & 1\\ \end{pmatrix} \cdot \begin{pmatrix} x \\ y \\ 1 \\\end{pmatrix} = \begin{pmatrix} x+t_x \\ y+t_y \\ 1 \\\end{pmatrix}
⎝⎛x′y′w′⎠⎞=⎝⎛100010txty1⎠⎞⋅⎝⎛xy1⎠⎞=⎝⎛x+txy+ty1⎠⎞
这样,进行平移操作时,向量不会被改变,但是点会被改变。
对于任何 ( x , y , w ) T (x,y,w)^T (x,y,w)T的点,我们都认为是 ( x / w , y / w , 1 ) T (x/w,y/w,1)^T (x/w,y/w,1)T,因此,在齐次坐标的表示下一个点加上一个点我们认为是取一个点的中点。
仿射变换(Affine transformation)都可以写成齐次坐标的形式。
(
x
′
y
′
1
)
=
(
a
b
t
x
c
d
t
y
0
0
1
)
⋅
(
x
y
1
)
\begin{pmatrix}x' \\y'\\1\\ \end{pmatrix} = \begin{pmatrix}a & b &t_x \\ c & d &t_y \\ 0 & 0 & 1\\ \end{pmatrix} \cdot \begin{pmatrix} x \\ y \\ 1 \\\end{pmatrix}
⎝⎛x′y′1⎠⎞=⎝⎛ac0bd0txty1⎠⎞⋅⎝⎛xy1⎠⎞
逆变换
变换的逆过程
乘原矩阵的逆矩阵即可(
A
×
M
×
M
−
1
=
A
A\times M\times M^{-1}=A
A×M×M−1=A)
变换的组合
变换与矩阵的操作一样不符合交换律。
如:
R
45
⋅
T
(
1
,
0
)
≠
T
(
1
,
0
)
⋅
R
45
R_{45}\cdot T_{(1,0)} \neq T_{(1,0)}\cdot R_{45}
R45⋅T(1,0)=T(1,0)⋅R45
对于关于点C的旋转,我们将其先平移到原点,再常规旋转,最后平移回C点,就可以完成关于C点的旋转。即: T ( c ) ⋅ R ( α ) ⋅ T ( − c ) T(c)\cdot R(\alpha)\cdot T(-c) T(c)⋅R(α)⋅T(−c)