- KVKV-X
計算
回転の相互変換
オイラー角 → 回転行列 (EulerToMatrix)

KV-X
- eulerAngle
- オイラー角 [roll, pitch, yaw]
- order
- 回転順 (0:XYZ, 1:XZY, 2:YXZ, 3:YZX, 4:ZXY, 5:ZYX)
- mat
- 回転行列
【例】
eulerAngle = [30, 30, 0]
order = 0
mat =
\begin{bmatrix}
0.866& 0& 0.5 \\
0.25& 0.866& -0.433 \\
-0.433& 0.5& 0.75
\end{bmatrix}
回転順 XZY \begin{align} &R_{xzy}=R_xR_zR_y \\ &= \begin{bmatrix} cos\theta_y cos\theta_z & -sin\theta_z & sin\theta_y cos\theta_z \\ cos\theta_x cos\theta_y sin\theta_z+sin\theta_x sin\theta_y & cos\theta_x cos\theta_z & cos\theta_x sin\theta_y sin\theta_z-sin\theta_x cos\theta_y \\ sin\theta_x cos\theta_y sin\theta_z-cos\theta_x sin\theta_y & sin\theta_x cos\theta_z & sin\theta_x sin\theta_y sin\theta_z+cos\theta_x cos\theta_y \end{bmatrix} \end{align}
回転順 YXZ \begin{align} &R_{yxz}=R_yR_xR_z \\ &= \begin{bmatrix} sin\theta_x sin\theta_y sin\theta_z+cos\theta_y cos\theta_z & sin\theta_x sin\theta_y sin\theta_z-cos\theta_y sin\theta_z & cos\theta_x sin\theta_y \\ cos\theta_x sin\theta_z & cos\theta_x cos\theta_z & -sin\theta_z \\ sin\theta_x cos\theta_y sin\theta_z-sin\theta_y cos\theta_z & sin\theta_x cos\theta_y cos\theta_z+sin\theta_y sin\theta_z & cos\theta_x cos\theta_y \end{bmatrix} \end{align}
回転順 YZX \begin{align} &R_{yzx}=R_yR_zR_x \\ &= \begin{bmatrix} cos\theta_y cos\theta_z & -cos\theta_x cos\theta_y sin\theta_z+sin\theta_x sin\theta_y & sin\theta_x cos\theta_y sin\theta_z+cos\theta_x sin\theta_y \\ sin\theta_x & cos\theta_x cos\theta_z & -sin\theta_x cos\theta_z \\ -sin\theta_y cos\theta_z & cos\theta_x sin\theta_y sin\theta_z+sin\theta_x cos\theta_y & -sin\theta_x sin\theta_y sin\theta_z+cos\theta_x cos\theta_y \end{bmatrix} \end{align}
回転順 ZXY \begin{align} &R_{zxy}=R_zR_xR_y \\ &= \begin{bmatrix} -sin\theta_x sin\theta_y sin\theta_z+cos\theta_y cos\theta_z & -cos\theta_x sin\theta_z+ & sin\theta_x cos\theta_y sin\theta_z+sin\theta_y cos\theta_z \\ sin\theta_x sin\theta_y cos\theta_z+cos\theta_y sin\theta_z & cos\theta_x cos\theta_z & -sin\theta_x cos\theta_y cos\theta_z+sin\theta_y sin\theta_z \\ -cos\theta_x sin\theta_y & sin\theta_x & cos\theta_x cos\theta_y \end{bmatrix} \end{align}
回転順 ZYX \begin{align} &R_{zyx}=R_zR_yR_x \\ &= \begin{bmatrix} cos\theta_y cos\theta_z & sin\theta_x sin\theta_y cos\theta_z-cos\theta_x sin\theta_z & cos\theta_x sin\theta_y cos\theta_z+sin\theta_x sin\theta_z \\ cos\theta_y sin\theta_z & sin\theta_x sin\theta_y sin\theta_z+cos\theta_x cos\theta_z & cos\theta_x sin\theta_y sin\theta_z+sin\theta_x cos\theta_z \\ -sin\theta_y & sin\theta_x cos\theta_y & cos\theta_x cos\theta_y \end{bmatrix} \end{align}
回転行列 → オイラー角 (MatrixToEuler)

KV-X
- mat
- 回転行列
- order
- 回転順 (0:XYZ, 1:XZY, 2:YXZ, 3:YZX, 4:ZXY, 5:ZYX)
- eulerAngle
- オイラー角 [roll, pitch, yaw]
【例】
mat =
\begin{bmatrix}
0.866& 0& 0.5 \\
0.25& 0.866& -0.433 \\
-0.433& 0.5& 0.75
\end{bmatrix}
order = 0
eulerAngle = [30, 30, 0]
回転順 XYZ \[\large \begin{align} \theta_x &= \begin{cases} \arctan \left( -\frac{m_{12}}{m_{22}} \right) &(\cos \theta_y \neq 0) \\ \arctan \left( \frac{m_{21}}{m_{11}} \right) &(otherwise) \end{cases} \\ \theta_y &= \arcsin (m_{02}) \\ \theta_z &= \begin{cases} \arctan \left( -\frac{m_{01}}{m_{00}} \right) &(\cos \theta_y \neq 0) \\ 0 &(otherwise) \end{cases} \\ \end{align} \]
回転順 XZY \[\large \begin{align} \theta_x &= \begin{cases} \arctan \left( \frac{m_{21}}{m_{11}} \right) &(\cos \theta_z \neq 0) \\ \arctan \left( -\frac{m_{12}}{m_{22}} \right) &(otherwise) \end{cases} \\ \theta_y &= \begin{cases} \arctan \left( \frac{m_{02}}{m_{00}} \right) &(\cos \theta_z \neq 0) \\ 0 &(otherwise) \end{cases} \\ \theta_z &= \arcsin (-m_{01}) \\ \end{align} \]
回転順 YXZ \[\large \begin{align} \theta_x &= \arcsin (-m_{12}) \\ \theta_y &= \begin{cases} \arctan \left( \frac{m_{02}}{m_{22}} \right) &(\cos \theta_x \neq 0) \\ \arctan \left( -\frac{m_{20}}{m_{00}} \right) &(otherwise) \end{cases} \\ \theta_z &= \begin{cases} \arctan \left( \frac{m_{10}}{m_{11}} \right) &(\cos \theta_x \neq 0) \\ 0 &(otherwise) \end{cases} \\ \end{align} \]
回転順 YZX \[\large \begin{align} \theta_x &= \begin{cases} \arctan \left( -\frac{m_{12}}{m_{11}} \right) &(\cos \theta_z \neq 0) \\ 0 &(otherwise) \end{cases} \\ \theta_y &= \begin{cases} \arctan \left( -\frac{m_{20}}{m_{00}} \right) &(\cos \theta_z \neq 0) \\ \arctan \left( \frac{m_{02}}{m_{22}} \right) &(otherwise) \\ \end{cases} \\ \theta_z &= \arcsin (m_{10}) \\ \end{align} \]
回転順 ZXY \[\large \begin{align} \theta_x &= \arcsin (m_{21}) \\ \theta_y &= \begin{cases} \arctan \left( -\frac{m_{20}}{m_{22}} \right) &(\cos \theta_x \neq 0) \\ 0 &(otherwise) \end{cases} \\ \theta_z &= \begin{cases} \arctan \left( -\frac{m_{01}}{m_{11}} \right) &(\cos \theta_x \neq 0) \\ \arctan \left( \frac{m_{10}}{m_{00}} \right) &(otherwise) \\ \end{cases} \\ \end{align} \]
回転順 ZYX \[\large \begin{align} \theta_x &= \begin{cases} \arctan \left( \frac{m_{21}}{m_{22}} \right) &(\cos \theta_y \neq 0) \\ 0 &(otherwise) \end{cases} \\ \theta_y &= \arcsin (-m_{20}) \\ \theta_z &= \begin{cases} \arctan \left( \frac{m_{10}}{m_{00}} \right) &(\cos \theta_y \neq 0) \\ \arctan \left( -\frac{m_{01}}{m_{11}} \right) &(otherwise) \\ \end{cases} \\ \end{align} \]
オイラー角 → クォータニオン (EulerToQuaternion)

KV-X
- eulerAngle
- オイラー角 [roll, pitch, yaw]
- order
- 回転順 (0:XYZ, 1:XZY, 2:YXZ, 3:YZX, 4:ZXY, 5:ZYX)
- qt
- クォータニオン [w, x, y, z]
【例】
eulerAngle = [30, 30, 0]
order = 0
qt = [0.933, 0.25, 0.25, 0.067]
回転順 XYZ \[\large \begin{bmatrix} -\sin \frac{\theta_x}{2}\sin \frac{\theta_y}{2}\sin \frac{\theta_z}{2} + \cos \frac{\theta_x}{2}\cos \frac{\theta_y}{2}\cos \frac{\theta_z}{2} \\ \cos \frac{\theta_x}{2}\sin \frac{\theta_y}{2}\sin \frac{\theta_z}{2} + \sin \frac{\theta_x}{2}\cos \frac{\theta_y}{2}\cos \frac{\theta_z}{2} \\ -\sin \frac{\theta_x}{2}\cos \frac{\theta_y}{2}\sin \frac{\theta_z}{2} + \cos \frac{\theta_x}{2}\sin \frac{\theta_y}{2}\cos \frac{\theta_z}{2} \\ \cos \frac{\theta_x}{2}\cos \frac{\theta_y}{2}\sin \frac{\theta_z}{2} + \sin \frac{\theta_x}{2}\sin \frac{\theta_y}{2}\cos \frac{\theta_z}{2} \\ \end{bmatrix} \]
回転順 XZY \[\large \begin{bmatrix} \sin \frac{\theta_x}{2}\sin \frac{\theta_y}{2}\sin \frac{\theta_z}{2} + \cos \frac{\theta_x}{2}\cos \frac{\theta_y}{2}\cos \frac{\theta_z}{2} \\ -\cos \frac{\theta_x}{2}\sin \frac{\theta_y}{2}\sin \frac{\theta_z}{2} + \sin \frac{\theta_x}{2}\cos \frac{\theta_y}{2}\cos \frac{\theta_z}{2} \\ \cos \frac{\theta_x}{2}\sin \frac{\theta_y}{2}\cos \frac{\theta_z}{2} - \sin \frac{\theta_x}{2}\cos \frac{\theta_y}{2}\sin \frac{\theta_z}{2} \\ \sin \frac{\theta_x}{2}\sin \frac{\theta_y}{2}\cos \frac{\theta_z}{2} + \cos \frac{\theta_x}{2}\cos \frac{\theta_y}{2}\sin \frac{\theta_z}{2} \\ \end{bmatrix} \]
回転順 YXZ \[\large \begin{bmatrix} \sin \frac{\theta_x}{2}\sin \frac{\theta_y}{2}\sin \frac{\theta_z}{2} + \cos \frac{\theta_x}{2}\cos \frac{\theta_y}{2}\cos \frac{\theta_z}{2} \\ \cos \frac{\theta_x}{2}\sin \frac{\theta_y}{2}\sin \frac{\theta_z}{2} + \sin \frac{\theta_x}{2}\cos \frac{\theta_y}{2}\cos \frac{\theta_z}{2} \\ -\sin \frac{\theta_x}{2}\cos \frac{\theta_y}{2}\sin \frac{\theta_z}{2} + \cos \frac{\theta_x}{2}\sin \frac{\theta_y}{2}\cos \frac{\theta_z}{2} \\ \cos \frac{\theta_x}{2}\cos \frac{\theta_y}{2}\sin \frac{\theta_z}{2} - \sin \frac{\theta_x}{2}\sin \frac{\theta_y}{2}\cos \frac{\theta_z}{2} \\ \end{bmatrix} \]
回転順 YZX \[\large \begin{bmatrix} -\sin \frac{\theta_x}{2}\sin \frac{\theta_y}{2}\sin \frac{\theta_z}{2} + \cos \frac{\theta_x}{2}\cos \frac{\theta_y}{2}\cos \frac{\theta_z}{2} \\ \sin \frac{\theta_x}{2}\cos \frac{\theta_y}{2}\cos \frac{\theta_z}{2} + \cos \frac{\theta_x}{2}\sin \frac{\theta_y}{2}\sin \frac{\theta_z}{2} \\ \sin \frac{\theta_x}{2}\cos \frac{\theta_y}{2}\sin \frac{\theta_z}{2} + \cos \frac{\theta_x}{2}\sin \frac{\theta_y}{2}\cos \frac{\theta_z}{2} \\ -\sin \frac{\theta_x}{2}\sin \frac{\theta_y}{2}\cos \frac{\theta_z}{2} + \cos \frac{\theta_x}{2}\cos \frac{\theta_y}{2}\sin \frac{\theta_z}{2} \\ \end{bmatrix} \]
回転順 ZXY \[\large \begin{bmatrix} -\sin \frac{\theta_x}{2}\sin \frac{\theta_y}{2}\sin \frac{\theta_z}{2} + \cos \frac{\theta_x}{2}\cos \frac{\theta_y}{2}\cos \frac{\theta_z}{2} \\ -\cos \frac{\theta_x}{2}\sin \frac{\theta_y}{2}\sin \frac{\theta_z}{2} + \sin \frac{\theta_x}{2}\cos \frac{\theta_y}{2}\cos \frac{\theta_z}{2} \\ \cos \frac{\theta_x}{2}\sin \frac{\theta_y}{2}\cos \frac{\theta_z}{2} + \sin \frac{\theta_x}{2}\cos \frac{\theta_y}{2}\sin \frac{\theta_z}{2} \\ \sin \frac{\theta_x}{2}\sin \frac{\theta_y}{2}\cos \frac{\theta_z}{2} + \cos \frac{\theta_x}{2}\cos \frac{\theta_y}{2}\sin \frac{\theta_z}{2} \\ \end{bmatrix} \]
回転順 ZYX \[\large \begin{bmatrix} \sin \frac{\theta_x}{2}\sin \frac{\theta_y}{2}\sin \frac{\theta_z}{2} + \cos \frac{\theta_x}{2}\cos \frac{\theta_y}{2}\cos \frac{\theta_z}{2} \\ \sin \frac{\theta_x}{2}\cos \frac{\theta_y}{2}\cos \frac{\theta_z}{2} - \cos \frac{\theta_x}{2}\sin \frac{\theta_y}{2}\sin \frac{\theta_z}{2} \\ \sin \frac{\theta_x}{2}\cos \frac{\theta_y}{2}\sin \frac{\theta_z}{2} + \cos \frac{\theta_x}{2}\sin \frac{\theta_y}{2}\cos \frac{\theta_z}{2} \\ -\sin \frac{\theta_x}{2}\sin \frac{\theta_y}{2}\cos \frac{\theta_z}{2} + \cos \frac{\theta_x}{2}\cos \frac{\theta_y}{2}\sin \frac{\theta_z}{2} \\ \end{bmatrix} \]
クォータニオン → オイラー角 (QuaternionToEuler)

KV-X
- qt
- クォータニオン [w, x, y, z]
- order
- 回転順 (0:XYZ, 1:XZY, 2:YXZ, 3:YZX, 4:ZXY, 5:ZYX)
- eulerAngle
- オイラー角 [roll, pitch, yaw]
【例】
qt = [0.933, 0.25, 0.25, 0.067]
order = 0
eulerAngle = [30, 30, 0]
回転順 XYZ \[\large \begin{align} \theta_x &= \begin{cases} \arctan \left( -\frac{2q_yq_z-2q_xq_w}{2q_w^2+2q_z^2-1} \right) &(\cos \theta_y \neq 0) \\ \arctan \left( \frac{2q_yq_z+2q_xq_w}{2q_w^2+2q_y^2-1} \right) &(otherwise) \end{cases} \\ \theta_y &= \arcsin (2q_xq_z+2q_yq_w) \\ \theta_z &= \begin{cases} \arctan \left( -\frac{2q_xq_y-2q_zq_w}{2q_w^2+2q_x^2-1} \right) &(\cos \theta_y \neq 0) \\ 0 &(otherwise) \end{cases} \\ \end{align} \]
回転順 XZY \[\large \begin{align} \theta_x &= \begin{cases} \arctan \left( \frac{2q_yq_z+2q_xq_w}{2q_w^2+2q_y^2-1} \right) &(\cos \theta_z \neq 0) \\ \arctan \left( -\frac{2q_yq_z-2q_xq_w}{2q_w^2+2q_z^2-1} \right) &(otherwise) \\ \end{cases} \\ \theta_y &= \begin{cases} \arctan \left( \frac{2q_xq_z+2q_yq_w}{2q_w^2+2q_x^2-1} \right) &(\cos \theta_z \neq 0) \\ 0 &(otherwise) \end{cases} \\ \theta_z &= \arcsin (-(2q_xq_y-2q_zq_w)) \\ \end{align} \]
回転順 YXZ \[\large \begin{align} \theta_x &= \arcsin (-(2q_yq_z-2q_xq_w)) \\ \theta_y &= \begin{cases} \arctan \left( \frac{2q_xq_z+2q_yq_w}{2q_w^2+2q_z^2-1} \right) &(\cos \theta_x \neq 0) \\ \arctan \left( -\frac{2q_xq_z-2q_yq_w}{2q_w^2+2q_z^2-1} \right) &(otherwise) \\ \end{cases} \\ \theta_z &= \begin{cases} \arctan \left( \frac{2q_xq_y+2q_zq_w}{2q_w^2+2q_y^2-1} \right) &(\cos \theta_x \neq 0) \\ 0 &(otherwise) \end{cases} \\ \end{align} \]
回転順 YZX \[\large \begin{align} \theta_x &= \begin{cases} \arctan \left( -\frac{2q_yq_z-2q_xq_w}{2q_w^2+2q_y^2-1} \right) &(\cos \theta_z \neq 0) \\ 0 &(otherwise) \end{cases} \\ \theta_y &= \begin{cases} \arctan \left( -\frac{2q_xq_z-2q_yq_w}{2q_w^2+2q_x^2-1} \right) &(\cos \theta_z \neq 0) \\ \arctan \left( \frac{2q_xq_z+2q_yq_w}{2q_w^2+2q_z^2-1} \right) &(otherwise) \\ \end{cases} \\ \theta_z &= \arcsin (-(2q_xq_y+2q_zq_w)) \\ \end{align} \]
回転順 ZXY \[\large \begin{align} \theta_x &= \arcsin (2q_yq_+2q_xq_w) \\ \theta_y &= \begin{cases} \arctan \left( -\frac{2q_xq_z-2q_yq_w}{2q_w^2+2q_z^2-1} \right) &(\cos \theta_x \neq 0) \\ 0 &(otherwise) \end{cases} \\ \theta_z &= \begin{cases} \arctan \left( -\frac{2q_xq_y-2q_zq_w}{2q_w^2+2q_y^2-1} \right) &(\cos \theta_x \neq 0) \\ \arctan \left( \frac{2q_xq_y+2q_zq_w}{2q_w^2+2q_x^2-1} \right) &(otherwise) \\ \end{cases} \\ \end{align} \]
回転順 ZYX \[\large \begin{align} \theta_x &= \begin{cases} \arctan \left( \frac{2q_yq_z+2q_xq_w}{2q_w^2+2q_z^2-1} \right) &(\cos \theta_y \neq 0) \\ 0 &(otherwise) \end{cases} \\ \theta_y &= \arcsin (-(2q_xq_z-2q_yq_w)) \\ \theta_z &= \begin{cases} \arctan \left( \frac{2q_xq_y+2q_zq_w}{2q_w^2+2q_x^2-1} \right) &(\cos \theta_y \neq 0) \\ \arctan \left( -\frac{2q_xq_y-2q_zq_w}{2q_w^2+2q_y^2-1} \right) &(otherwise) \\ \end{cases} \\ \end{align} \]
クォータニオン → 回転行列 (QuaternionToMatrix)

KV-X
- qt
- クォータニオン [w, x, y, z]
- mat
- 回転行列
【例】
qt = [0.933, 0.25, 0.25, 0.067]
order = 0
mat =
\begin{bmatrix}
0.866& 0& 0.5 \\
0.25& 0.866& -0.433 \\
-0.433& 0.5& 0.75
\end{bmatrix}
回転行列 → クォータニオン (MatrixToQuaternion)

KV-X
- mat
- 回転行列
- conv
- 変換候補 (0-3)
- qt
- クォータニオン [w, x, y, z]
-
【例】
mat = \begin{bmatrix} 0.866& 0& 0.5 \\ 0.25& 0.866& -0.433 \\ -0.433& 0.5& 0.75 \end{bmatrix} conv = 0
qt = [0.933, 0.25, 0.25, 0.067]
参考URL
Quita 回転行列、クォータニオン、オイラー角の相互変換 https://qiita.com/aa_debdeb/items/3d02e28fb9ebfa357eaf
