summaryrefslogtreecommitdiff
path: root/sample.py
diff options
context:
space:
mode:
authorStan Seibert <stan@mtrr.org>2011-09-16 14:27:46 -0400
committerStan Seibert <stan@mtrr.org>2011-09-16 14:27:46 -0400
commit084dfd08b714faefaea77cb7dc04d2e93dc04b1d (patch)
tree5be8c1f1d30dc52d74c70c4964ec54f66294c265 /sample.py
parentcfecff941fc619eb7269128afc62d9c11ae78aff (diff)
downloadchroma-084dfd08b714faefaea77cb7dc04d2e93dc04b1d.tar.gz
chroma-084dfd08b714faefaea77cb7dc04d2e93dc04b1d.tar.bz2
chroma-084dfd08b714faefaea77cb7dc04d2e93dc04b1d.zip
File reorganization to move toward standard python package layout
Diffstat (limited to 'sample.py')
-rw-r--r--sample.py56
1 files changed, 0 insertions, 56 deletions
diff --git a/sample.py b/sample.py
deleted file mode 100644
index 1909370..0000000
--- a/sample.py
+++ /dev/null
@@ -1,56 +0,0 @@
-import numpy as np
-from chroma.transform import rotate
-
-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
-
-def flashlight(phi=np.pi/4, direction=(0,0,1), size=None, dtype=np.double):
- theta, u = np.random.uniform(0.0, 2*np.pi, size), \
- np.random.uniform(np.cos(phi), 1, size)
-
- c = np.sqrt(1-u**2)
-
- if np.equal(direction, (0,0,1)).all():
- rotation_axis = (0,0,1)
- rotation_angle = 0.0
- else:
- rotation_axis = np.cross((0,0,1), direction)
- rotation_angle = \
- -np.arccos(np.dot(direction, (0,0,1))/np.linalg.norm(direction))
-
- if size is None:
- return rotate(np.array([c*np.cos(theta), c*np.sin(theta), u]),
- rotation_angle, rotation_axis)
-
- points = np.empty((size, 3), dtype)
-
- points[:,0] = c*np.cos(theta)
- points[:,1] = c*np.sin(theta)
- points[:,2] = u
-
- return rotate(points, rotation_angle, rotation_axis)