3D Transformation

和二维点同理,我们把三维点表示成四维 Homogeneous Coordinates

[xyz][wxwywzw]=[xyz1] \begin{bmatrix}x\\y\\z\end{bmatrix}\to \begin{bmatrix}wx\\wy\\wz\\w\end{bmatrix}=\begin{bmatrix}x\\y\\z\\1\end{bmatrix}

Translation

[100tx010ty001tz0001][xyz1]=[x+txy+tyz+tz1] \begin{bmatrix}1&0&0&t_x\\0&1&0&t_y\\0&0&1&t_z\\0&0&0&1\end{bmatrix}\begin{bmatrix}x\\y\\z\\1\end{bmatrix}=\begin{bmatrix}x+t_x\\y+t_y\\z+t_z\\1\end{bmatrix}

Scaling

[sx0000sy0000sz00001][xyz1]=[xsxysyzsz1] \begin{bmatrix}s_x&0&0&0\\0&s_y&0&0\\0&0&s_z&0\\0&0&0&1\end{bmatrix}\begin{bmatrix}x\\y\\z\\1\end{bmatrix}=\begin{bmatrix}xs_x\\ys_y\\zs_z\\1\end{bmatrix}

Rotation

我们默认是右手系,即默认逆时针旋转.

  • xx-axis 旋转:[10000cosθsinθ00sinθcosθ00001]\begin{bmatrix}1&0&0&0\\0&\color{red}{\cos\theta}&\color{red}{-\sin\theta}&0\\0&\color{red}{\sin\theta}&\color{red}{\cos\theta}&0\\0&0&0&1\end{bmatrix}

  • yy-axis 旋转:[cosθ0sinθ00100sinθ0cosθ00001]\begin{bmatrix}\color{red}{\cos\theta}&0&\color{red}{\sin\theta}&0\\0&1&0&0\\\color{red}{-\sin\theta}&0&\color{red}{\cos\theta}&0\\0&0&0&1\end{bmatrix}

  • zz-axis 旋转:[cosθsinθ00sinθcosθ0000100001]\begin{bmatrix}\color{red}{\cos\theta}&\color{red}{-\sin\theta}&0&0\\\color{red}{\sin\theta}&\color{red}{\cos\theta}&0&0\\0&0&1&0\\0&0&0&1\end{bmatrix}

Affine Transformation

多个 Translation/Rotation/Scaling/Reflection 可以合成一个 Affine 矩阵. (并且这些 Basic Operations 也都是 Affine Transformations). 其 Matrix Form 是

[xyz1]=[abcmdefnghpl0001][xyz1] \begin{bmatrix}x'\\y'\\z'\\1\end{bmatrix}=\begin{bmatrix}a&b&c&m\\d&e&f&n\\g&h&p&l\\0&0&0&1\end{bmatrix}\begin{bmatrix}x\\y\\z\\1\end{bmatrix}

在 VRML 里,Transformation 定义为数据结构:

1
2
3
4
5
6
Transform {
translate dx, dy, dz;
rotation ax, ay, az, theta; // 绕 (ax,ay,az) 旋转 theta 度
scale sz, sy, sz;
children [...];
}

生效顺序为  scalerotationtranslation\texttt{ scale\(\to\)rotation\(\to\)translation}