summaryrefslogtreecommitdiff
path: root/sample.py
diff options
context:
space:
mode:
authorAnthony LaTorre <telatorre@gmail.com>2011-06-12 21:31:22 -0400
committerAnthony LaTorre <telatorre@gmail.com>2011-06-12 21:31:22 -0400
commit870236b3c4950762a73247c68023a8dee6e14a7b (patch)
treea9b634e0ef43f17c00e725972240d48673a708b6 /sample.py
parente06a8b551c730e3d1111fc571c5d48edb85f70ce (diff)
downloadchroma-870236b3c4950762a73247c68023a8dee6e14a7b.tar.gz
chroma-870236b3c4950762a73247c68023a8dee6e14a7b.tar.bz2
chroma-870236b3c4950762a73247c68023a8dee6e14a7b.zip
added some fun models; added some untested code to implement absorption, scattering, reflection, and refraction
Diffstat (limited to 'sample.py')
-rw-r--r--sample.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/sample.py b/sample.py
new file mode 100644
index 0000000..b494384
--- /dev/null
+++ b/sample.py
@@ -0,0 +1,29 @@
+import numpy as np
+
+def uniform_sphere(size=None, dtype=np.double):
+ """
+ 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.
+ """
+
+ 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)
+
+ if size is None:
+ return np.array([c*np.cos(theta), c*np.sin(theta), u])
+
+ points = np.empty((size, 3), dtype)
+
+ points[:,0] = c*np.cos(theta)
+ points[:,1] = c*np.sin(theta)
+ points[:,2] = u
+
+ return points