跳到主要内容

旋转

绕轴旋转

  • 定义向量:vec1=(x1,y1,z1,1)\overrightarrow{vec_1} = (x_1,y_1,z_1,1)
  • 定义旋转后的向量:vec2=(x2,y2,z2,1)\overrightarrow{vec_2} = (x_2,y_2,z_2,1)
  • 定义向量长度为:len=veclen = |\overrightarrow{vec}|
  • 定义向量与起始轴的夹角为α\alpha^\circ
  • 定义向量绕轴旋转β\beta^\circ
  • c=cos(β)c = \cos(\beta)
  • s=sin(β)s = \sin(\beta)

旋转方向

  • 当物体绕 z 轴,从 x 轴正半轴向 y 轴正半轴逆时针旋转时,是正向旋转,反之为负。
  • 当物体绕 x 轴,从 y 轴正半轴向 z 轴正半轴逆时针旋转时,是正向旋转,反之为负。
  • 当物体绕 y 轴,从 z 轴正半轴向 x 轴正半轴逆时针旋转时,是正向旋转,反之为负。

定义起始轴(弧度为 0)

  • 当物体绕 z 轴,x 轴正半轴为起始轴,往 y 轴正半轴为正
  • 当物体绕 x 轴,y 轴正半轴为起始轴,往 z 轴正半轴为正
  • 当物体绕 y 轴,z 轴正半轴为起始轴,往 x 轴正半轴为正

绕 Z 轴旋转

/*
Y


└──────── X
*/
x2=len×cos(α+β)=len×(cos(α)cos(β)sin(α)sin(β))=len×cos(α)×cos(β)len×sin(α)×sin(β)=x1×cos(β)y1×sin(β)x_2 = len \times \cos(\alpha+\beta) = len \times (\cos(\alpha)\cos(\beta) - \sin(\alpha)\sin(\beta)) = len \times \cos(\alpha) \times \cos(\beta) - len \times \sin(\alpha) \times \sin(\beta) = x_1 \times \cos(\beta) - y_1 \times \sin(\beta) y2=len×sin(α+β)=len×(sin(α)cos(β)+cos(α)sin(β))=len×sin(α)×cos(β)+len×cos(α)×sin(β)=y1×cos(β)+x1×sin(β)y_2 = len \times \sin(\alpha+\beta) = len \times (\sin(\alpha)\cos(\beta) + \cos(\alpha)\sin(\beta)) = len \times \sin(\alpha) \times \cos(\beta) + len \times \cos(\alpha) \times \sin(\beta) = y_1 \times \cos(\beta) + x_1 \times \sin(\beta) vec2=[cs00sc0000100001]×vec1\overrightarrow{vec_2} = \begin{bmatrix} {c} & {s} & 0 & 0 \\ {-s} & {c} & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \\ \end{bmatrix} \times \overrightarrow{vec_1}

绕 X 轴旋转

/*
Y


Z ────────┘
*/
y2=len×cos(α+β)=len×(cos(α)cos(β)sin(α)sin(β))=len×cos(α)×cos(β)len×sin(α)×sin(β)=y1×cos(β)z1×sin(β)y_2 = len \times \cos(\alpha+\beta) = len \times (\cos(\alpha)\cos(\beta) - \sin(\alpha)\sin(\beta)) = len \times \cos(\alpha) \times \cos(\beta) - len \times \sin(\alpha) \times \sin(\beta) = y_1 \times \cos(\beta) - z_1 \times \sin(\beta) z2=len×sin(α+β)=len×(sin(α)cos(β)+cos(α)sin(β))=len×sin(α)×cos(β)+len×cos(α)×sin(β)=z1×cos(β)+y1×sin(β)z_2 = len \times \sin(\alpha+\beta) = len \times (\sin(\alpha)\cos(\beta) + \cos(\alpha)\sin(\beta)) = len \times \sin(\alpha) \times \cos(\beta) + len \times \cos(\alpha) \times \sin(\beta) = z_1 \times \cos(\beta) + y_1 \times \sin(\beta) vec2=[10000cs00sc00001]×vec1\overrightarrow{vec_2} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & {c} & {s} & 0 \\ 0 & {-s} & {c} & 0 \\ 0 & 0 & 0 & 1 \\ \end{bmatrix} \times \overrightarrow{vec_1}

绕 Y 轴旋转

/*
┌──────── X


Z
*/
z2=len×cos(α+β)=len×(cos(α)cos(β)sin(α)sin(β))=len×cos(α)×cos(β)len×sin(α)×sin(β)=z1×cos(β)x1×sin(β)z_2 = len \times \cos(\alpha+\beta) = len \times (\cos(\alpha)\cos(\beta) - \sin(\alpha)\sin(\beta)) = len \times \cos(\alpha) \times \cos(\beta) - len \times \sin(\alpha) \times \sin(\beta) = z_1 \times \cos(\beta) - x_1 \times \sin(\beta) x2=len×sin(α+β)=len×(sin(α)cos(β)+cos(α)sin(β))=len×sin(α)×cos(β)+len×cos(α)×sin(β)=x1×cos(β)+z1×sin(β)x_2 = len \times \sin(\alpha+\beta) = len \times (\sin(\alpha)\cos(\beta) + \cos(\alpha)\sin(\beta)) = len \times \sin(\alpha) \times \cos(\beta) + len \times \cos(\alpha) \times \sin(\beta) = x_1 \times \cos(\beta) + z_1 \times \sin(\beta) vec2=[c0s00100s0c00001]×vec1\overrightarrow{vec_2} = \begin{bmatrix} {c} & 0 & {-s} & 0 \\ 0 & 1 & 0 & 0 \\ {s} & 0 & {c} & 0 \\ 0 & 0 & 0 & 1 \\ \end{bmatrix} \times \overrightarrow{vec_1}