1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

四元数

1
Last updated at Posted at 2020-05-18

主に3DCG関係で自分がよく使用する数式の自分用メモです。

表記と定義

q = ( q_0, q_1, q_2, q_3 )\\
q \cdot p = \sum q_i p_i\\
\begin{vmatrix} q \end{vmatrix} = \sqrt{q \cdot q} = \sqrt{ q_0^2 + q_1^2 + q_2^2 + q_3^2 }\\
\begin{align}
q \times p =
( &q_0p_0 - q_1p_1 - q_2p_2 - q_3p_3,\\
  &q_0p_1 + q_1p_0 + q_2p_3 - q_3p_2,\\
  &q_0p_2 - q_1p_3 + q_2p_0 + q_3p_1,\\
  &q_0p_3 + q_1p_2 - q_2p_1 + q_3p_0 )
\end{align}

逆数

i = (0,1,0,0)\\
j = (0,0,1,0)\\
k = (0,0,0,1)\\
q^{-1} = - \frac{0.5}{ \begin{vmatrix} q \end{vmatrix} } (q + i \times  q \times i + j \times q \times j + k \times q \times k)

線形補完

q, p の補完, t=[0,1]

\begin{align}
s &= \left\{
\begin{array}{ll}
1-t & (q \cdot p \geq 0) \\
t-1 & (q \cdot p \lt 0)
\end{array}
\right.\\
r &= s \cdot q + t \cdot p\\
Lerp(q,p,t) &= \frac{r}{\begin{vmatrix} r \end{vmatrix}}
\end{align}

球面線形補間

q, p の補完, t=[0,1]

\begin{align}
a &= \cos^{-1} \begin{vmatrix} q \cdot p \end{vmatrix} \\
s &= \left\{
\begin{array}{ll}
1 & (q \cdot p \geq 0) \\
-1 & (q \cdot p \lt 0)
\end{array}
\right.\\
r &= \frac{1}{\sin(a)} \big( s \cdot \sin(a (1 - t)) \cdot q + \sin(at) \cdot p \big)\\
Slerp(q,p,t) &= \frac{r}{\begin{vmatrix} r \end{vmatrix}}
\end{align}

任意のベクトルを回転軸とする四元数

回転軸ベクトル:a、回転角:θ

\acute{a} = \frac{a}{\begin{vmatrix} a \end{vmatrix}}\\
q = ( \cos(0.5 \theta), \; \acute{a}_0 \sin ( 0.5 \theta ), \; \acute{a}_1 \sin ( 0.5 \theta ), \; \acute{a}_2 \sin ( 0.5 \theta ) )

回転行列へ変換

qと等価な回転行列M

M = \begin{pmatrix}
q_0^2 + q_1^2 - q_2^2 - q_3^2 &
2 (q_1q_2 - q_0q_3) &
2 (q_1q_3 +q_0q_2)\\

2 (q_1q_2 + q_0q_3) &
q_0^2 - q_1^2 + q_2^2 - q_3^2 &
2 (q_2q_3 - q_0q_1)\\

2 (q_1q_3 - q_0q_2) &
2 (q_2q_3 + q_0q_1) &
q_0^2 - q_1^2 - q_2^2 + q_3^2
\end{pmatrix}

回転行列からの変換

回転行列Mと等価なq

\begin{align}
q_0 &= 0.25 \sqrt{chop(M_{00} + M_{11} + M_{22} + 1)}\\
q_1 &= 0.25 \cdot a \sqrt{chop(M_{00} - M_{11} - M_{22} + 1)}\\
q_2 &= 0.25 \cdot b \sqrt{chop(-M_{00} + M_{11} - M_{22} + 1)}\\
q_3 &= 0.25 \cdot c \sqrt{chop(-M_{00} - M_{11} + M_{22} + 1)}\\

chop(x) &= \left\{
\begin{array}{ll}
x & (x \geq 0) \\
0 & (x \lt 0)
\end{array}
\right.\\

a &= \left\{
\begin{array}{ll}
-1 & (q_0 > 0) \; \cap \; (M_{21} - M_{12} < 0) \\
1 & else
\end{array}
\right.\\

b &= \left\{
\begin{array}{ll}
-1 & ( (q_0 > 0) \cap (M_{02} - M_{20} < 0) ) \; \cup \;
     ( (q_0 = 0) \cap (q_1 \neq 0) \cap (M_{10} + M_{02} < 0)) \\
1 & else
\end{array}
\right.\\

c &= \left\{
\begin{array}{ll}
-1 & ( (q_0 > 0) \cap (M_{10} - M_{01} < 0) ) \; \cup \;
     ( (q_0 = 0) \cap (q_1 \neq 0) \cap (M_{02} + M_{20} < 0))  \; \cup \;
     ( (q_0 = 0) \cap (q_1 = 0) \cap (M_{21} + M_{12} < 0)) \\
1 & else
\end{array}
\right.\\

\end{align}\\

※後で正規化が必要

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?