Create a gist now

Instantly share code, notes, and snippets.

@pervognsen /hopf.txt
Last active Feb 17, 2017

What would you like to do?
This note is in response to this article, particularly the final section on three degrees of freedom:
It notes that "Marsaglia hand-wavingly presented a method for the 4D sphere". I hope to give some insight
into how this method may be obtained and how it relates to some relatively commonplace mathematical ideas.
The unit quaternions may be embedded in C^2 as pairs of complex numbers (z1, z2) satisfying |z1|^2 + |z2|^2 = 1.
If we write z1 and z2 in polar coordinates as z1 = r1 exp(i t1) and z2 = r2 exp(i t2), this is equivalent to
r1^2 + r2^2 = 1, and hence t1 and t2 are unconstrained and may be chosen arbitrarily. The equation for r1 and
r2 is just the formula for a unit circle in R^2, so its solutions may be parameterized in polar coordinates
as well: r1 = cos(s) and r2 = sin(s) where s is a real number. Hence a unit quaternion through this embedding
may be written in the form
z1 = cos(s) exp(i t1)
z2 = sin(s) exp(i t2)
It's clear that t1 and t2 vary freely between 0 and 2 pi, and s must be restricted between 0 and pi/2 to
obtain a unique parameterization, so that cos(s) and sin(s) are both between 0 and 1 (sign changes can
be expressed as phase changes to t1 and t2).
These are the so-called Hopf coordinates. Related ideas such as the Hopf fibration play a key role in topology.
To see how volume is distorted in this coordinate system, we will pull back the volume form from C^2.
If we fix s at some value, varying t1 traces out a circle and varying t2 independently traces out an orthogonal
circle, generating a torus. The length of the t1 circle is scaled by cos(s) and the length of the t2 circle is
scaled by sin(s), and hence the area of the torus in C^2 is scaled by cos(s) sin(s) relative to area in the
(t1, t2) domain. This is a loose argument that the volume form's pullback is cos(s) sin(s) ds /\ dt1 /\ dt2.
To make a more direct connection with the uniform_quat algorithm, change coordinates from s to u = sin(s). We
get du = cos(s) ds, so the volume form becomes sin(s) du /\ dt1 /\ dt2 = u du /\ dt1 /\ dt2. Then
z1 = u exp(i t1) and z2 = sqrt(1 - u^2) exp(i t2) where u now varies between 0 and 1. Imagine picking z1 and z2
sequentially, so that z1's coordinates are first picked as a point within the unit disk, and then z2's coordinates
are picked as a point on the circle of radius sqrt(1 - |z1|^2) = sqrt(1 - u^2). Rather than doing the second part
directly, it picks an arbitrary point within the unit disk and then rescales the result to the proper radius.
This accounts for the factor of u in the volume form, so that the distribution becomes uniform.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment