LoginSignup
9

More than 5 years have passed since last update.

クォータニオン(四元数)のメモ

Last updated at Posted at 2013-07-17

Quaternionの掛け算の公式

A = (a; U)
B = (b; V)
AB = (ab - U・V; aV + bU + U×V)
※「・」は内積、「×」は外積、U, Vはともにベクトル
 「;」の左が実部、右が虚部。
※ただし、計算しやすいよう本来はVxUとなるところを、UxVとしている点に注意。

Quaternionの中の数値

\begin{equation}
q =
\begin{vmatrix}
\cos\left(\frac{\theta}{2}\right) &\sin\left(\frac{\theta}{2}\right)n \\
\end{vmatrix}
\end{equation}
\\

=
\begin{vmatrix}
\cos\left(\frac{\theta}{2}\right) &(\sin\left(\frac{\theta}{2}\right)nx &\sin\left(\frac{\theta}{2}\right)ny &\sin\left(\frac{\theta}{2}\right)nz ) \\
\end{vmatrix}

※nはベクトル。 下はベクトル成分を分解して表記。

Quaternionを生成する関数の例

function makeQuaternion(radian, vector) {
    var ret = new Quaternion(),
        ccc = 0,
        sss = 0,
        axis = new Vector3(vector.toArray()),
        norm = vector.norm();

    if (norm <= 0.0) {
        return ret;
    }

    axis.normalize();

    //cos(θ/2)
    ccc = cos(0.5 * radian);

    //sin(θ/2)
    sss = sin(0.5 * radian);

    var t = ccc; //実部
    axis.multiplyScalar(sss); //虚部

    //計算した値をQuaternionにセット
    ret.set(t, axis);

    return ret;
}

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
9