Heres more python than you can shake a telescope at. I just used @ProfRob's algorithm. This is just a python script, the real answer to the question is @ProfRob's answer and I've just scripted it. The mathematics behind generating statistically uniform distributions is explained very nicely there as well.
Python is below the plots. You can see on an X-Y graph they thin out at the top and bottom.
The 3D plot is live, you can use your cursor and move the sphere around. Of course not HERE :-), but in your own python window if you run the script.
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
halfpi, pi, twopi = [f*np.pi for f in [0.5, 1, 2]]
degs, rads = 180/pi, pi/180
# do radians first, then convert later
nstars = 2000
ran1, ran2 = np.random.random(2*nstars).reshape(2, -1)
RA = twopi * (ran1 - 0.5)
dec = np.arcsin(2.*(ran2-0.5)) # Hey Barry Carter!
funcs = [np.cos, np.sin]
cosRA, sinRA = [f(RA) for f in funcs]
cosdec, sindec = [f(dec) for f in funcs]
x = cosRA * cosdec
y = sinRA * cosdec
z = sindec
decs = (np.arange(11)-5) * halfpi / 6.
RAs = (np.arange(12)-5) * halfpi / 6.
theta = np.linspace(0, twopi, 101)
costh, sinth = [f(theta) for f in funcs]
zerth = np.zeros_like(theta)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1, projection='3d')
ax.plot(x, y, z, '.k')
# lines of declination
xvals = costh * np.cos(decs)[:, None]
yvals = sinth * np.cos(decs)[:, None]
zvals = zerth + np.sin(decs)[:, None]
for x, y, z in zip(xvals, yvals, zvals):
plt.plot(x, y, z, '-g', linewidth=0.8)
# lines of Right Ascention
xvals = costh * np.cos(RAs)[:, None]
yvals = costh * np.sin(RAs)[:, None]
zvals = sinth + np.zeros_like(RAs)[:, None]
for x, y, z in zip(xvals, yvals, zvals):
plt.plot(x, y, z, '-r', linewidth=0.8)
ax.set_xlim(-1.1, 1.1)
ax.set_ylim(-1.1, 1.1)
ax.set_zlim(-1.1, 1.1)
ax.view_init(elev=30, azim=15)
plt.show()
if True:
plt.figure()
plt.plot(degs*RA, degs*dec, '.k')
plt.xlim(-180, 180)
plt.ylim(-90, 90)
plt.show()
DEC=Arccos(np.random.uniform(-90,90))
? $\endgroup$arccos
because it makes more sense (length of a declination line is proportional tocos
, notsin
), but I'm guessingarcsin
yields the same distribution. $\endgroup$