计算机图形学入门II
Transformation Cont.
一、视图(View)变换
- Scale
$$
S(s_x,s_y,s_z)=
\begin{pmatrix}
s_x & 0 & 0 & 0\\
0 & s_y & 0 & 0\\
0 & 0 & s_z & 0\\
0 & 0 & 0 & 1\\
\end{pmatrix}
$$ - Translation
$$
T(t_x,t_y,t_z)=
\begin{pmatrix}
1 & 0 & 0 & t_x\\
0 & 1 & 0 & t_y\\
0 & 0 & 1 & t_z\\
0 & 0 & 0 & 1\\
\end{pmatrix}
$$ - Rotation(around x-,y-,z-)
- 绕哪一轴旋转,对应行列不变
- 绕y-旋转矩阵特殊性
$$
R_x(\alpha)=
\begin{pmatrix}
1 & 0 & 0 & 0\\
0 & cos\alpha & -sin\alpha & 0\\
0 & sin\alpha & cos\alpha & 0\\
0 & 0 & 0 & 1\\
\end{pmatrix}
$$
$$
R_y(\alpha)=
\begin{pmatrix}
cos\alpha & 0 & sin\alpha & 0\\
0 & 1 & 0 & 0\\
-sin\alpha & 0 & cos\alpha & 0\\
0 & 0 & 0 & 1\\
\end{pmatrix}
$$
$$
R_z(\alpha)=
\begin{pmatrix}
cos\alpha & -sin\alpha & 0 & 0\\
sin\alpha & cos\alpha & 0 & 0\\
0 & 0 & 1 & 0\\
0 & 0 & 0 & 1\\
\end{pmatrix}
$$
- 罗德里格斯旋转公式(Rodrigues’ Rotation Formula)
Rotation by angle α around axis n
$$
R(n,\alpha)=cos(\alpha)I+(1-cos(\alpha))nn^T+sin(\alpha)
\begin{pmatrix}
0 & -n_z & n_y\\
n_z & 0 & -n_x\\
-n_y & n_x & 0\\
\end{pmatrix}
$$
二、投影(Projection)变换
- 正交投影(Orthographic projection)&透视投影(Perspective projection)
- 正交投影(Orthographic projection)
$$
M_{ortho}=
\begin{bmatrix}
\frac{2}{r-l} & 0 & 0 & 0\\
0 & \frac{2}{t-b} & 0 & 0\\
0 & 0 & \frac{2}{n-f} & 0\\
0 & 0 & 0 & 1\\
\end{bmatrix}
\begin{bmatrix}
1 & 0 & 0 & -\frac{r+l}{2}\\
0 & 1 & 0 & -\frac{t+b}{2}\\
0 & 0 & 1 & -\frac{n+f}{2}\\
0 & 0 & 0 & 1\\
\end{bmatrix}
$$
最终结果将其规范约束到$[-1,1]^3$这样一个空间内
3. 透视投影(Perspective projection)
- 空间内有一点$(x,y,z,1)$,若给坐标乘上$k\neq0$得到$(kx,ky,kz,k)$,其仍然表示$(x,y,z)$这一点
- 思路是将这样一个椎体挤成一个立方体然后进行正交投影变换
- Tip:近远平面以及中心轴永远不变
$$
M_{persp}=M_{ortho}M_{persp\rightarrow ortho}
$$