Quaternion Random
#クォータニオン #乱数 #回転 #数学
一様ランダムなクォータニオンを生成する
3つの一様分布から生成できる
$ q = \begin{pmatrix} \sqrt{1-u} \ \sin(2 \pi v) \\ \sqrt{1-u} \ \cos(2 \pi v) \\ \sqrt{u} \ \sin(2 \pi w) \\ \sqrt{u} \ \cos(2 \pi w) \end{pmatrix}
w, x, y, zの順番は気にしなくていい気がする
See: http://planning.cs.uiuc.edu/node198.html
Code
code:js
function quatRandom() {
const u = Math.random();
const v = TAU * Math.random();
const w = TAU * Math.random();
const sqrtU = Math.sqrt( u );
const sqrt1U = Math.sqrt( 1.0 - u );
return [
sqrt1U * Math.sin( v ),
sqrt1U * Math.cos( v ),
sqrtU * Math.sin( w ),
sqrtU * Math.cos( w ),
];
}