オイラー角による回転行列の表現まとめ

免責・注意:本記事は、その正しさを一切保証しない。できるだけ出典を記すようにするが、特に、要出典・要確認等と書かれただけの箇所は注意が必要である。また、現時点では未完成で、随時追記・更新していくつもりである。

右手系・左手系について

座標系を考えるとき、右手系と左手系のどちらかを用いることになる。本記事では右手系のことしか考えない。左手系について知りたい人は、以下の内容を全て自分で変換し直して考えるか、別の記事を当たる必要がある。

右手系の採用例

左手系の採用例

世界座標系とモデル座標系のどちらの座標系を基準とみるか:Extrinsic (Fixed) vs. Intrinsic (Mobile)

本記事では extrinsic (fixed) なオイラー角表現のことしか考えない。Intrinsic (mobile) なオイラー角表現を暗黙的に採用しているシステムもあるので注意が必要である。

Extrinsic (fixed) な表現では世界座標系 (world coordinates) の座標軸を基準に回転することを考える。

Extrinsic rotations are elemental rotations that occur about the axes of the fixed coordinate system xyz. The XYZ system rotates, while xyz is fixed.

引用元:Wikipedia. Euler angles. https://en.wikipedia.org/wiki/Euler_angles

一方で、intrinsic (mobile) な表現ではモデル座標系 (model coordinates; local coordinates) の座標軸を基準に回転することを考える。そのため、回転を適用する度に次に回転する際の基準軸が世界座標系から見たときに変わる点で注意が必要である。

Intrinsic rotations are elemental rotations that occur about the axes of a coordinate system XYZ attached to a moving body.

引用元:Wikipedia. Euler angles. https://en.wikipedia.org/wiki/Euler_angles

Extrinsic (fixed) でも intrinsic (mobile) でも、どちらも同等な回転を表現することができる。

For example, the fixed XYZ Euler angle convention is described by the x→y→z sequence, while the mobile ZYX Euler angle convention is described by the z'→y'→x' sequence, but both are equivalent, as we will see later.

引用元:How is orientation in space represented with Euler angles? https://www.mecademic.com/resources/Euler-angles/Euler-angles

また、extrinsic (fixed) な回転と intrinsic (mobile) な回転を混ぜて考えることも可能である。ただし実際にこれが有益になることは少ないと思われる。

That said, each of the twelve combinations is equivalent to three other sequences. In other words, each Euler angle convention can be described in four different ways. For example, the ZYX convention is equivalent to the sequences z→y→x, x'→y'→z', y→z'→x and y→x→z'.

引用元:Mecademic, Inc. How is orientation in space represented with Euler angles? https://www.mecademic.com/resources/Euler-angles/Euler-angles

Extrinsic (Fixed) Euler XYZ

世界座標系の  x 軸周りに  \theta_x 回転させ、続いて世界座標系の  y 軸周りに  \theta_y 回転させ、続いて世界座標系の  z 軸周りに  \theta_z 回転させるような回転について、そのような記述の方法を extrinsic (fixed) Euler XYZ と表現したい。実際には単に Euler XYZ と呼ばれることも多いが、extrinsic と intrinsic の違いについて常に意識しておいた方が安全である。

そのような回転は以下の回転行列で与えられる。

\displaystyle{
\mathbf{R} = \mathbf{R}_z(\theta_z) \mathbf{R}_y(\theta_y) \mathbf{R}_x(\theta_x) \in \mathbb{R}^{3 \times 3}
}

あるモデル座標系の点  \mathbf{x}^\text{model} \in \mathbb{R}^{3 \times 1} を、上のような extrinsic (fixed) Euler XYZ によって世界座標系に配置する際には、世界座標系上での座標  \mathbf{x}^\text{world} \in \mathbb{R}^{3 \times 1}

\displaystyle{
\mathbf{x}^\text{world} = \mathbf{R}_z(\theta_z) \mathbf{R}_y(\theta_y) \mathbf{R}_x(\theta_x) \mathbf{x}^\text{model}
}

で与えられる。

XYZ とは回転行列を適用する順番を表現している。OpenGL の Legacy APIs では post-multiplication が採用されているため、記述するときには

glRotated(theta_z, 0.0, 0.0, 1.0);
glRotated(theta_y, 0.0, 1.0, 0.0);
glRotated(theta_x, 1.0, 0.0, 0.0);

という順番になると思われる。

Extrinsic (Fixed) Euler XYZ の採用例

  • Maya のデフォルト(TODO:要出典)

オイラー角を三次元ベクトルで表現する際の注意

変数の格納順に注意が必要である。名前が XYZ となっていても、

vec3 euler_angles = { theta_x, theta_y, theta_z };

のような順序で変数を格納するのが必ずしも唯一の方法ではない。例えば、回転行列の掛け算の式に現れる順に

vec3 euler_angles = { theta_z, theta_y, theta_x };

と変数を格納する実装もあり得る。これは Eigen の eulerAngles() で採用されている(TODO:要確認)。