summaryrefslogtreecommitdiff
path: root/photon.py
diff options
context:
space:
mode:
Diffstat (limited to 'photon.py')
-rw-r--r--photon.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/photon.py b/photon.py
new file mode 100644
index 0000000..3472c1e
--- /dev/null
+++ b/photon.py
@@ -0,0 +1,35 @@
+import time
+import numpy as np
+
+def uniform_sphere(size=None):
+ """
+ Generate random points isotropically distributed across the unit sphere.
+
+ Args:
+ - size: int, *optional*
+ Number of points to generate. If no size is specified, a single
+ point is returned.
+
+ source: Weisstein, Eric W. "Sphere Point Picking." Mathworld.
+ """
+
+ t0 = time.time()
+
+ theta, u = np.random.uniform(0.0, 2*np.pi, size), \
+ np.random.uniform(-1.0, 1.0, size)
+
+ c = np.sqrt(1-u**2)
+
+ x = c*np.cos(theta)
+ y = c*np.sin(theta)
+ z = u
+
+ points = np.empty((x.size, 3))
+ points[:,0] = x
+ points[:,1] = y
+ points[:,2] = z
+
+ if size is None:
+ return points[0]
+ else:
+ return points