I need a rigorous explanation of Shoemake method to sample uniformly from the group of unit quaternions

202 Views Asked by At

I know and understand the subgroup algorithm to sample from uniform distribution on the rotation group $SO\left( 3 \right)$, following the following steps:

  1. sample $\theta_{1}$ from $\text{Unif}\left[ 0,\, 1 \right]$ and define $R z$, the $3$D rotation about zaxis, of angle $2 \pi \theta_{1}$
  2. sample uniformly an element $v$ on the sphere $S^{2}$, following either of the two methods I defined in a SO answer, here: Uniform sampling arroung a unit sphere.
  3. Define $w=(v+e_3)/||v+e_3||$, where $e_3=[0,0,1]$.
  4. return the random rotation $\left( 2 w w^{\top} - I_{3} \right) \cdot R z$.

On Wikipedia is given without any mathematical arguments (only a reference to a Shoemake algorithm, Shoemake, Ken ($1992-01-01$), Kirk, DAVID (ed.), "III.$6$ - UNIFORM RANDOM ROTATIONS", Graphics Gems III, San Francisco: Morgan Kaufmann, pp. $124–132$) a method to sample uniformly from the group $S^{3}$, of unit quaternions. I know why a random unit quaternion defines a random rotation, but I cannot understand the arguments given in the Shoemake paper, where a unit quaternion defining a rotation of axis $u$, $\left| \left| u \right| \right| = 1$, and angle $\theta$, is $q = \left( \sin\left( \frac{\theta}{2} \right) \cdot u,\, \cos\left( \frac{\theta}{2} \right) \right)$, while on wikipedia it is $q =\left( \cos\left( \frac{\theta}{2} \right), \sin\left( \frac{\theta}{2} \right) \cdot u \right)$.

I give below the Shoemake presentation of his method, and I'd be greatful if someone could confirm or infirm its correctness.

Shoemake notation: Let $X_{0}$, $X_{1}$ and $X_{2}$ be three iid $\text{Unif}\left[ 0,\, 1 \right)$. Compute two uniformly distributed angles, $\theta_{1} = 2 \pi X_{1}$ and $\theta_{2} = 2 \pi X_{2}$, and their sines and cosines, $s_{1},\, c_{1},\, s_{2},\, c_{2}$. Also compute $r_{1} = \sqrt{1 - X_{0}}$ and $r_{2} = \sqrt{X_{0}}$· The unit quaternion with components $\left[ s_{1} r_{1},\, c_{1} r_{1},\, s_{2} r_{2},\, c_{2} r_{2} \right]$ is a uniform sample from $S^{3}$.

Shoemake arguments that I cannot understand:

"In terms of quaternions, a rotation around z has the form $\left[ 0,\, 0,\, s,\, c \right]$, while a rotation pointing z in an arbitrary direction has the form $\left[ x,\, y,\, 0,\, w \right]$". (Why the third coordinate is $0$? If the rotation of random axis would be $2 v v^{\top}-I_{3}$, then its rotation angle is π, and a quaternion corresponding to this rotation is in Shoemake notation $\left( \sin\left( \frac{\pi}{2} \right) v, \cos\left( \frac{\pi}{2} \right) \right) = \left(v,\, 0 \right)$).

Shoemake explains: "If the direction is to be uniformly distributed, $w$ must be distributed as the square root of a uniform distribution, and $x$ and $y$ must be a uniform plane rotation times $\sqrt{1 - w^{2}}$. The square root is necessary because the rotated $z$ value should be uniform for a point uniformly distributed on a sphere. The $z$ value comes out to be $2 w^{2} - 1$; substituting $w = \sqrt{X_{0}}$ gives $2 X_{0} - 1$, a uniform deviate between $-1$ and $+1$, as required. The product of the $z$ placement with the z rotation is $\left[ c x + s y,\, -s x + c y,\, s w, c w \right]$, which is just one step away from the final code. We know, since this should give points uni- formly distributed on a hypersphere, that all components have the same kind of distribution. In particular, the first two components are the product of two uniform plane rotations times a magnitude of $\sqrt{1 - X_{0}}$, which can be reduced to a single plane rotation of the correct magnitude, like the last two components. The result is the code stated".