Javaプログラミング

トップページ      |      目次
←前へ      次へ→

  • 回転行列
    • 図形の回転と回転行列
    • ユークリッド空間において図形を回転させる時、座標値(座標ベクトル)に回転行列をかけることにより回転変換することができる
    • 2次元の回転行列
    • \[ R(\theta)= \begin{bmatrix} \cos \theta & -\sin \theta \\ \sin \theta & \cos \theta \\ \end{bmatrix} \]
    • 2次元の回転行列を使った回転変換 \[ \begin{bmatrix} x' \\ y' \end{bmatrix} = \begin{bmatrix} \cos \theta & -\sin \theta \\ \sin \theta & \cos \theta \\ \end{bmatrix} \begin{bmatrix} x\\ y \end{bmatrix} \] すなわち \[ x' = x \cos \theta - y \sin \theta \] \[ y' = x \sin \theta + y \cos \theta \] 実行結果
      原点(黒丸)を中心に正方形(黒)を正方向(時計回り)に
      30度の回転変換を施した結果(赤)
      ※コンピュータスクリーンの座標系はY座標が下向きが正になっているので、
      通常の座標系と逆向きになることに注意
      GIFイメージ

      コード
      
      //30度正方向(時計回り)に回転
      theta=30*Math.PI/180;
      rx=x*Math.cos(theta)-y*Math.sin(theta);
      ry=x*Math.sin(theta)+y*Math.cos(theta);
      
      サンプルコード

    • 3次元の回転行列
    • x軸回転 \[ R_x(\theta)= \begin{bmatrix} 1 & 0 & 0 \\ 0 & \cos \theta & -\sin \theta \\ 0 & \sin \theta & \cos \theta \\ \end{bmatrix} \] y軸回転 \[ R_y(\theta)= \begin{bmatrix} \cos \theta & 0 & \sin \theta \\ 0 & 1 & 0 \\ - \sin \theta & 0 & \cos \theta \\ \end{bmatrix} \] z軸回転 \[ R_z(\theta)= \begin{bmatrix} \cos \theta & - \sin \theta & 0 \\ \sin \theta & \cos \theta & 0 \\ 0 & 0 & 1 \end{bmatrix} \]
    • 3次元の回転行列を使った回転変換
      • x軸回転
      • \[ \begin{bmatrix} x' \\ y' \\ z' \end{bmatrix} = \begin{bmatrix} 1 & 0 & 0 \\ 0 & \cos \theta & -\sin \theta \\ 0 & \sin \theta & \cos \theta \\ \end{bmatrix} \begin{bmatrix} x \\ y \\ z \end{bmatrix} \] すなわち \[ x' = x \] \[ y' = y \cos \theta - z \sin \theta \] \[ z' = y \sin \theta + z \cos \theta \]
      実行結果
      X軸(赤)を中心に立方体を正方向(+Xから見て時計回り)に
      30度の回転変換を施した結果(グレー)
      ※コンピュータスクリーンの座標系はY座標が下向きが正になっているので、
      通常の座標系と逆向きになることに注意
      GIFイメージ
      コード
      
      //30度正方向(時計回り)にX軸回転
      theta=30*Math.PI/180;
      ry=y*Math.cos(theta)-z*Math.sin(theta);
      rz=y*Math.sin(theta)+z*Math.cos(theta);				
      
      • y軸回転
      • \[ \begin{bmatrix} x' \\ y' \\ z' \end{bmatrix} = \begin{bmatrix} \cos \theta & 0 & \sin \theta \\ 0 & 1 & 0 \\ - \sin \theta & 0 & \cos \theta \\ \end{bmatrix} \begin{bmatrix} x \\ y \\ z \end{bmatrix} \] すなわち \[ x' = x \cos \theta + z \sin \theta \] \[ y' = y \] \[ z' = -x \sin \theta + z \cos \theta \]
      実行結果
      Y軸(緑)を中心に立方体を正方向(+Yから見て時計回り)に
      30度の回転変換を施した結果(グレー)
      ※コンピュータスクリーンの座標系はY座標が下向きが正になっているので、
      通常の座標系と逆向きになることに注意
      GIFイメージ
      コード
      
      //30度正方向(時計回り)にY軸回転
      theta=30*Math.PI/180;
      rx=x*Math.cos(theta)+z*Math.sin(theta);
      rz=-x*Math.sin(theta)+z*Math.cos(theta);
      
      • z軸回転
      • \[ \begin{bmatrix} x' \\ y' \\ z' \end{bmatrix} = \begin{bmatrix} \cos \theta & - \sin \theta & 0 \\ \sin \theta & \cos \theta & 0 \\ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ z \end{bmatrix} \] すなわち \[ x' = x \cos \theta - y \sin \theta \] \[ y' = x \sin \theta + y \cos \theta \] \[ z' = z \]
      実行結果
      Z軸(青)を中心に立方体を正方向(+Zから見て時計回り)に
      30度の回転変換を施した結果(グレー)
      ※コンピュータスクリーンの座標系はY座標が下向きが正になっているので、
      通常の座標系と逆向きになることに注意
      GIFイメージ
      コード
      
      //30度正方向(時計回り)にZ軸回転
      theta=30*Math.PI/180;
      rx=x*Math.cos(theta)-y*Math.sin(theta);
      ry=x*Math.sin(theta)+y*Math.cos(theta);
      
        サンプルコード


      ←前へ      次へ→