# Methods for sampling evenly-spaced points from various domains, using Fibonacci spirals
# (The sampling is *not* from a uniform random distribution. There is nothing random about this.)
import numpy as np

# Golden ratio
phi = (1 + np.sqrt(5)) / 2


# Returns n sample points from a Fibonacci spiral on the unit disk
def unitdisk(n):
    r2 = np.linspace(1/(2*n), 1-1/(2*n), n)
    r = np.sqrt(r2)
    theta = (2*np.pi*phi) * np.arange(n)
    x, y = r*np.cos(theta), r*np.sin(theta)
    return np.array([x, y]).transpose()


# Returns n sample points from a Fibonacci spiral on the unit sphere
def unitsphere(n):
    # z-coordinates of sample points
    z = np.linspace(1-(1/n), -1+(1/n), n)

    # Longitude and latitude of sample points
    lon = (2*np.pi*phi) * np.arange(n)
    lat = np.arcsin(z)

    # x,y-coordinates of sample points
    x, y = np.cos(lon)*np.cos(lat), np.sin(lon)*np.cos(lat)

    # Return a numpy.Array containing the sample points
    return np.array([x, y, z]).transpose()
