矩阵旋转

绕原点二维旋转


旋转矩阵,其中\theta为逆时针旋转角

$\begin{bmatrix} x'\\ y'\\ \end{bmatrix} = \begin{bmatrix} cos\theta&-sin\theta\\ sin\theta&cos\theta\\ \end{bmatrix} \cdot \begin{bmatrix} x\\ y\\ \end{bmatrix}$

绕任意点的二维旋转

需要绕任意点旋转时,可以把这种情况转换到绕原点的旋转,思路如下:

  1. 首先将旋转点移动到原点处
  2. 执行如2所描述的绕原点的旋转
  3. 再将旋转点移回到原来的位置

旋转矩阵 = 平移矩阵 * 旋转矩阵 * 平移矩阵

$\begin{bmatrix} 1&0&tx\\ 0&1&ty\\ 0&0&1\\ \end{bmatrix} \cdot \begin{bmatrix} cos\theta&-sin\theta&0\\ sin\theta&cos\theta&0\\ 0&0&1\\ \end{bmatrix} \cdot \begin{bmatrix} 1&0&-tx\\ 0&1&-ty\\ 0&0&1\\ \end{bmatrix} = \begin{bmatrix} cos\theta&-sin\theta&(1-cos\theta)tx + ty*sin\theta\\ sin\theta&cos\theta&(1-cos\theta)ty - tx*sin\theta\\ 0&0&1\\ \end{bmatrix}$

旋转矩阵