前言
本篇总结与之前的总结不太一样,与图形无关,是关于坐标变换的总结,主要使用矩阵计算完成,同样可以自行阅读参考文献了解,以下是本人的自行总结内容。
参考文献:《计算机图形学——用OpenGL实现(第2版)》 清华大学出版社
矩阵表示向量
我们可以用矩阵去表示一个点的坐标或平面向量,表示方法如下 Q = [ x y 1 ] = [ x y 1 ] T Q = \begin{gathered} \begin{bmatrix} x \\ y \\ 1 \end{bmatrix} \end{gathered} =\begin{gathered} \begin{bmatrix} x & y & 1 \end{bmatrix} \end{gathered} ^ T Q=⎣⎡xy1⎦⎤=[xy1]T*最后的1是为了方便计算拓展的
平移
假设点 Q Q Q要按向量 P P P做平移,结果为 S S S,可以表示为 S = [ S x S y 1 ] = [ 1 0 P x 0 1 P y 0 0 1 ] [ Q x Q y 1 ] = [ Q x + P x Q y + P y 1 ] S = \begin{gathered} \begin{bmatrix} S_x \\ S_y \\ 1 \end{bmatrix} \end{gathered} = \begin{gathered} \begin{bmatrix} 1 & 0 & P_x \\ 0 & 1 & P_y \\ 0 & 0 & 1 \end{bmatrix} \end{gathered} \begin{gathered} \begin{bmatrix} Q_x \\ Q_y \\ 1 \end{bmatrix} \end{gathered} = \begin{gathered} \begin{bmatrix} Q_x + P_x \\ Q_y + P_y \\ 1 \end{bmatrix} \end{gathered} S=⎣⎡SxSy1⎦⎤=⎣⎡100010PxPy1⎦⎤⎣⎡QxQy1⎦⎤=⎣⎡Qx+PxQy+Py1⎦⎤
缩放
假设向量 Q Q Q做 P x P_x Px和 P y P_y Py的缩放,结果为 S S S S = [ S x S y 1 ] = [ P x 0 0 0 P y 0 0 0 1 ] [ Q x Q y 1 ] = [ Q x P x Q y P y 1 ] S = \begin{gathered} \begin{bmatrix} S_x \\ S_y \\ 1 \end{bmatrix} \end{gathered} = \begin{gathered} \begin{bmatrix} P_x & 0 & 0 \\ 0 & P_y & 0 \\ 0 & 0 & 1 \end{bmatrix} \end{gathered} \begin{gathered} \begin{bmatrix} Q_x \\ Q_y \\ 1 \end{bmatrix} \end{gathered} = \begin{gathered} \begin{bmatrix} Q_xP_x \\ Q_yP_y \\ 1 \end{bmatrix} \end{gathered} S=⎣⎡SxSy1⎦⎤=⎣⎡Px00