I am looking for an algorithm to uniformly sample the surface of a unit sphere.
I have been reading in https://mathworld.wolfram.com/SpherePointPicking.html.
Their approach appears to translate as:
def randomPoints(n):
u = np.random.uniform(0, 1, size=n)
v = np.random.uniform(0, 1, size=n)
theta = 2*np.pi*u
phi = np.arccos(2*v - 1)
return theta, phi
Where theta = [0, 2pi) and phi = [0, pi]
I would like to know if anyone can tell me if this is the best approach to achieve a uniform distribution around the surface of a unit sphere. Or if there is some other algorithm which will reach an isotropic state faster.
EDIT: I have also been trying with a method by George Marsaglia 1972, The Annals of Mathematical Statistics, vol. 43, No. 2, 645 - 646.
r = np.sqrt(np.random.uniform(0.0, 1.0, n))
t = np.random.uniform(0, 2*np.pi, n)
v1, v2 = r*np.cos(t), r*np.sin(t)
s = v1*v1 + v2*v2
a = 2*v1*(np.sqrt(1-s))
b = 2*v2*(np.sqrt(1-s))
c = 1-2*s
theta = np.arctan2(b, a)
phi = np.arccos(c/(np.sqrt(a**2 + b**2 + c**2)))
Best Regards