[Math] Vector Picking on the Unit Sphere

3drandom variablesspherical coordinatesspherical-geometryvector analysis

Imagine a vector from the center of a unit sphere to its surface:

enter image description here

Now imagine a second vector generated in indentical fashion. Given the first vector, how can I generate vectors to uniformally distribute the angle between them (θ).

My first thought was to use spherical coordinates — however this generates a non-uniform distribution (as most points picked will be near the equatorial circumference, relative to the first vector):
Angle distribution

Next I read this Wolfram Alpha article on sphere point picking. But that yields nearly identical results… the {X,Y,Z} endpoint is now uniformally distributed, but the angle (θ) between the two unit vectors is not.

The closest I've come is to pick the end point of the second vector on a unit circle which I place in plane centered on the sphere's center point. Then I take the point and rotate about the original vector by a random amount using the equation for rotation about a line in arbitrary space (such that the unit sphere's center can be place in arbitrary space).

This gives this distribution:
enter image description here
Which is relatively flat on [30,150], but spikes near the peaks.

Any ideas on how to pick the second vector so as to give a uniform angular distribution?

Best Answer

In spherical coordinates, the surface area of a sphere is proportional to (1 minus the cosine of the polar angle), as measured from a chosen "pole" on the sphere. So perhaps after choosing your first vector, the second vector would be chosen so that $ \ -1 \ \le \cos \theta \le +1 \ $ is uniformly distributed for your second vector, $ \ \theta \ $ being the plane angle between them, and the "azimuthal angle" $ \ 0 \le \phi < 2 \pi\ $ for the direction of the second vector being uniformly distributed.