Created
April 3, 2014 06:42
-
-
Save goulu/9949374 to your computer and use it in GitHub Desktop.
Generate N evenly distributed points on the unit sphere
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def points_on_sphere(N): | |
""" Generate N evenly distributed points on the unit sphere centered at | |
the origin. Uses the 'Golden Spiral'. | |
Code by Chris Colbert from the numpy-discussion list. | |
""" | |
import numpy as np | |
phi = (1 + np.sqrt(5)) / 2 # the golden ratio | |
long_incr = 2*np.pi / phi # how much to increment the longitude | |
dz = 2.0 / float(N) # a unit sphere has diameter 2 | |
bands = np.arange(N) # each band will have one point placed on it | |
z = bands * dz - 1 + (dz/2) # the height z of each band/point | |
r = np.sqrt(1 - z*z) # project onto xy-plane | |
az = bands * long_incr # azimuthal angle of point modulo 2 pi | |
x = r * np.cos(az) | |
y = r * np.sin(az) | |
return x, y, z |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
code found on http://docs.enthought.com/mayavi/mayavi/auto/example_delaunay_graph.html
description of the problem (in french) : http://www.drgoulu.com/2007/01/31/comment-placer-n-points-regulierement-sur-une-sphere/