📜  计算机图形学– 3D旋转变换

📅  最后修改于: 2021-08-27 17:32:31             🧑  作者: Mango

与2D中的旋转变换相比,3D中的旋转更细微差别,因为在3D旋转中,我们必须处理3轴(x,y,z)。

任意

共有三种旋转方式,在这里我们可以使对象平行于(或沿着)特定轴旋转,以使对象围绕其旋转的坐标保持不变,而其余两个坐标将发生变化。可能的旋转有以下三种:

  • 绕X轴旋转,
  • 绕Y轴旋转,
  • 绕Z轴旋转。

1)绕x轴旋转: 在这种旋转中,对象平行于x轴(主轴)旋转,其中x坐标 保持不变,其余两个坐标yz仅更改。考虑在3D空间中具有初始坐标P(x,y,z)的点使其平行于主轴线(x轴)旋转。坐标位置将变为P’(x,y,z)。

旋转变换矩阵用于计算新的位置坐标P’,如下所示:

\large\hspace{4cm}\R_x=\left[\begin{matrix}1&0&0&0\\ 0&cos(\theta)&sin(\theta)&0\\ 0&-sin(\theta)&cos(\theta)&0\\ 0&0&0&1\end{matrix}\right]\\ \newline \\\,\,\hspace{5cm}where\, \theta\, is\, rotation\,angle.\\

\\ \large\hspace{5cm}\mathbf{P'[x_n\,\,y_n\,\,z_n\,\,1]=P[x\,y\,z\,1].R_x}\newline \newline\hspace{5cm}X_n = X_o \hspace{2cm} \textbf{no\,\,change\,\,in\,\,x-coordinate}\\ \hspace{5cm} Y_n = Y_o\,.cosθ\,-\,Z_o\,.sinθ \newline \hspace{5cm} Z_n = Y_o\,.sinθ + Z_o\,.cosθ\\ \\\\ \hspace{3cm}\mathbf{P'[x_n\,\,y_n\,\,z_n\,\,1]\hspace{0.2cm}is\hspace{0.2cm}the\hspace{0.2cm}new\hspace{0.2cm}position\hspace{0.2cm}of\hspace{0.2cm}coordinate\hspace{0.2cm}P[x\,\,y\,\,x\,\,1].}

沿x轴旋转

2)绕y轴旋转:在这种旋转中,对象平行于y轴(主轴)旋转,其中 y坐标保持不变,而两个坐标x和z的其余部分仅发生变化。

\large\hspace{4cm}\R_y=\left[\begin{matrix}cos(\theta)&0&-sin(\theta)&0\\ 0&1&0&0\\ sin(\theta)&0&cos(\theta)&0\\ 0&0&0&1\end{matrix}\right]\\ \newline \\\,\,\hspace{5cm}where\, \theta\, is\, rotation\,angle.\\ \newline \newline

沿y轴旋转

考虑3D空间中具有初始坐标P(x,y,z)的点使其平行于主轴线(y轴)旋转。坐标位置将变为P’(x,y,z)。

\large\hspace{5cm}\mathbf{P'[x\,y\,z\,1]=P[x\hspace{0.2cm}y\hspace{0.2cm} z\hspace{0.2cm}1].R_y}\\\\ \hspace{5cm} X_n =  x_o\,.cosθ+z_o\,.sinθ \newline \hspace{5cm} Y_n = y_o \hspace{2cm} \textbf{no\,\,change\,\,in\,\,y-coordinate}\\ \newline \hspace{5cm} Z_n = z_o\,.cos(θ)\,-\,x_o\,.sin(θ)\\ \,\, \hspace{3cm}\mathbf{P'[x_n\hspace{0.2cm}y_n\hspace{0.2cm}z_n\hspace{0.2cm}1]\hspace{0.2cm}is\hspace{0.2cm}the\hspace{0.2cm}new\hspace{0.2cm}position\hspace{0.2cm}of\hspace{0.2cm}coordinate\hspace{0.2cm}P[x\hspace{0.2cm}y\hspace{0.2cm}z\hspace{0.2cm}1].} \\

3)绕z轴旋转:在这种旋转中,对象平行于z轴(主轴)旋转,其中 z坐标保持不变,其余两个坐标xy仅改变。
\large\hspace{4cm}\R_z=\left[\begin{matrix}cos(\theta)&sin(\theta)&0&0\\ -sin(\theta)&cos(\theta)&0&0\\ 0&0&1&0\\ 0&0&0&1\end{matrix}\right]\\ \newline \\\,\,\hspace{5cm}where\, \theta\, is\, rotation\,angle. \\ \newline \newline

沿z轴旋转

考虑3D空间中具有初始坐标P(x,y,z)的点使其平行于主轴线(y轴)旋转。坐标位置将变为P’(x,y,z)。

\large\hspace{5cm}\mathbf{P'[x_n\hspace{0.2cm}y_n\hspace{0.2cm}z_n\hspace{0.2cm}1]=P[x\hspace{0.2cm}y\hspace{0.2cm}z\hspace{0.2cm}1].R_z}\\\\ \newline \hspace{5cm} X_n = x_o\,.cosθ\,-\,y_o\,.sinθ \\ \hspace{5cm} Y_n = x_o\,.sinθ + y_o\,.cosθ \newline \hspace{5cm} Z_n = z_o \hspace{2cm} \textbf{no\,\,change\,\,in\,\,Z-coordinate}\\ \hspace{3cm}\mathbf{P'[x_n\hspace{0.2cm}y_n\hspace{0.2cm}z_n\hspace{0.2cm}1]\hspace{0.2cm}is\hspace{0.2cm}the\hspace{0.2cm}new\hspace{0.2cm}position\hspace{0.2cm}of\hspace{0.2cm}coordinate\hspace{0.2cm}P[x\hspace{0.2cm}y\hspace{0.2cm}x\hspace{0.2cm}1].}

注意:始终将逆时针方向的旋转角度视为+ ve,而始终将逆时针方向的旋转角度视为-ve。这是3D旋转中始终遵循的通用约定。

在立方体“ OABCDEFG”上执行旋转变换,并将其绕y轴沿逆时针方向旋转45 *。

我们得到下图:

图。1

现在,我们将沿(平行于)y轴应用旋转变换,即:

\large\hspace{2cm}\R_y=\left[\begin{matrix}cos(\theta)&0&-sin(\theta)&0\\ 0&1&0&0\\ sin(\theta)&0&cos(\theta)&0\\ 0&0&0&1\end{matrix}\right]\\ \hspace{4cm}where\, \theta\, is\, rotation\,angle.\\ \newline

应用旋转变换后的坐标O变为:

\newline \mathbf{\large\hspace{2cm}\ O'[x\,\,y\,\,z\,\,1]=[0\hspace{0.1cm}0\hspace{0.1cm}0\hspace{0.1cm}1]\left[\begin{matrix}\frac{1}{\sqrt{2}}&0&\frac{-1}{\sqrt{2}}&0\\\\ 0&1&0&0\\\\ \frac{1}{\sqrt{2}}&0&\frac{1}{\sqrt{2}}&0\\\\ 0&0&0&1\end{matrix}\right] \hspace{0.1cm} =[0\hspace{0.1cm}0\hspace{0.1cm}0\hspace{0.1cm}1]} \newline \hspace{2cm}\mathbf{O'[x,y,z]=[0,0,0]} \newline

应用旋转变换后的坐标A变为:

\newline \mathbf{\large\hspace{2cm}\ A'[x\,\,y\,\,z\,\,1]=[0\hspace{0.2cm}4\hspace{0.2cm}0\hspace{0.2cm}1]\left[\begin{matrix}\frac{1}{\sqrt{2}}&0&\frac{-1}{\sqrt{2}}&0\\\\ 0&1&0&0\\\\ \frac{1}{\sqrt{2}}&0&\frac{1}{\sqrt{2}}&0\\\\ 0&0&0&1\end{matrix}\right] \hspace{0.1cm} =[0\hspace{0.2cm}4\hspace{0.2cm}0\hspace{0.2cm}1]} \newline \textbf{Here you can see that the Y-coordinate remains unchanged, \\i.e A[0,4,0]=A'[0,4,0].} \newline

应用旋转变换后的坐标B变为:

\newline \large \mathbf{\hspace{2cm}\ B'[x\,\,y\,\,z\,\,1]=[0\hspace{0.2cm}4\hspace{0.2cm}4\hspace{0.2cm}1]\left[\begin{matrix}\frac{1}{\sqrt{2}}&0&\frac{-1}{\sqrt{2}}&0\\\\ 0&1&0&0\\\\ \frac{1}{\sqrt{2}}&0&\frac{1}{\sqrt{2}}&0\\\\ 0&0&0&1\end{matrix}\right] \hspace{0.1cm} =[\frac{4}{\sqrt{2}}\hspace{0.2cm}4\hspace{0.2cm}\frac{4}{\sqrt{2}}\hspace{0.2cm}1]} \newline \hspace{2cm}\mathbf{B'[x,y,z]=[2\sqrt{2},4,2\sqrt{2}]} \\

应用旋转变换后的坐标C变为:

\newline \large \mathbf{\hspace{2cm}\ C'[x\,\,y\,\,z\,\,1]=[4\hspace{0.2cm}4\hspace{0.2cm}0\hspace{0.2cm}1]\left[\begin{matrix}\frac{1}{\sqrt{2}}&0&\frac{-1}{\sqrt{2}}&0\\\\ 0&1&0&0\\\\ \frac{1}{\sqrt{2}}&0&\frac{1}{\sqrt{2}}&0\\\\ 0&0&0&1\end{matrix}\right] \hspace{0.1cm} =[\frac{4}{\sqrt{2}}\hspace{0.3cm}4\hspace{0.3cm}\frac{-4}{\sqrt{2}}\hspace{0.3cm}1]} \newline \hspace{2cm}\mathbf{C'[x,y,z]=[2\sqrt{2},4,-2\sqrt{2}]} \\

应用旋转变换后的坐标D变为:

\newline \large \mathbf{\hspace{2cm}\ D'[x\,\,y\,\,z]=[4\hspace{0.2cm}4\hspace{0.2cm}4\hspace{0.2cm}1]\left[\begin{matrix}\frac{1}{\sqrt{2}}&0&\frac{-1}{\sqrt{2}}&0\\\\ 0&1&0&0\\\\ \frac{1}{\sqrt{2}}&0&\frac{1}{\sqrt{2}}&0\\\\ 0&0&0&1\end{matrix}\right] \hspace{0.1cm} =[(\frac{4}{\sqrt{2}}+\frac{4}{\sqrt{2}})\hspace{0.3cm}4\hspace{0.3cm}(\frac{4}{\sqrt{4}}-\frac{4}{\sqrt{2}})\hspace{0.3cm}1]}\newline \hspace{2cm}\mathbf{D'[x,y,z]=[4\sqrt{2},4,0]} \\

应用旋转变换后的坐标E变为:

\newline \large {\hspace{2cm}\mathbf{ E'[x\,\,y\,\,z\,\,1]=[4\hspace{0.2cm}0\hspace{0.2cm}0\hspace{0.2cm}1]\left[\begin{matrix}\frac{1}{\sqrt{2}}&0&\frac{-1}{\sqrt{2}}&0\\\\ 0&1&0&0\\\\ \frac{1}{\sqrt{2}}&0&\frac{1}{\sqrt{2}}&0\\\\ 0&0&0&1\end{matrix}\right] \hspace{0.1cm} =[\frac{4}{\sqrt{2}}\hspace{0.3cm}0\hspace{0.3cm}\frac{-4}{\sqrt{2}}\hspace{0.3cm}1]}} \\ \hspace{2cm}\mathbf{E'[x,y,z]=[2\sqrt{2},0,-2\sqrt{2}]} \newline

应用旋转变换后的坐标F变为:

\newline \large\mathbf{\hspace{2cm}\ F'[x\,\,y\,\,z\,\,1]=[0\hspace{0.2cm}0\hspace{0.2cm}4\hspace{0.2cm}1]\left[\begin{matrix}\frac{1}{\sqrt{2}}&0&\frac{-1}{\sqrt{2}}&0\\\\ 0&1&0&0\\\\ \frac{1}{\sqrt{2}}&0&\frac{1}{\sqrt{2}}&0\\\\ 0&0&0&1\end{matrix}\right] \hspace{0.1cm} =[\frac{4}{\sqrt{2}}\hspace{0.3cm}0\hspace{0.3cm}\frac{4}{\sqrt{2}}\hspace{0.3cm}1]} \newline \hspace{2cm}\mathbf{F'[x,y,z]=[2\sqrt{2},0,2\sqrt{2}]} \newline

应用旋转变换后的坐标G变为:

\newline \large \mathbf{\hspace{2cm}\ G'[x\,\,y\,\,z\,\,1]=[4\hspace{0.2cm}0\hspace{0.2cm}4\hspace{0.2cm}1]\left[\begin{matrix}\frac{1}{\sqrt{2}}&0&\frac{-1}{\sqrt{2}}&0\\\\ 0&1&0&0\\\\ \frac{1}{\sqrt{2}}&0&\frac{1}{\sqrt{2}}&0\\\\ 0&0&0&1\end{matrix}\right] \hspace{0.1cm} =[(\frac{4}{\sqrt{2}}+\frac{4}{\sqrt{2}})\hspace{0.3cm}0\hspace{0.3cm}(\frac{4}{\sqrt{2}}-\frac{4}{\sqrt{2})}\hspace{0.3cm}1]} \newline \hspace{2cm}\mathbf{G'[x,y,z]=[4\sqrt{2},0,0]}\newline

因此,在成功对多维数据集“ OABCDEF”执行旋转变换后获得的结果多维数据集将如下所示: