summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorArun Isaac2021-03-26 14:17:19 +0530
committerArun Isaac2021-03-26 14:18:31 +0530
commit05f6d0e94e5603caa769137508cf005bea3c9adc (patch)
treef27d73adefb3728c8fa4a1938677b01c76a3a965 /src
parent7fdcd4d355274bdd70fa1de0ff9723790a45634f (diff)
downloadsambal-05f6d0e94e5603caa769137508cf005bea3c9adc.tar.gz
sambal-05f6d0e94e5603caa769137508cf005bea3c9adc.tar.lz
sambal-05f6d0e94e5603caa769137508cf005bea3c9adc.zip
Move planar angle generation into random_on_cap.
* src/sambal/sambal.py (random_planar_angle_pdf): Move function into
random_on_cap.
Diffstat (limited to 'src')
-rw-r--r--src/sambal/sambal.py22
1 files changed, 10 insertions, 12 deletions
diff --git a/src/sambal/sambal.py b/src/sambal/sambal.py
index 3a35438..c42ea44 100644
--- a/src/sambal/sambal.py
+++ b/src/sambal/sambal.py
@@ -39,17 +39,6 @@ def rotate_from_nth_canonical(x, axis):
             - axisn*(xn*s + a*(axisn - 1))/b
     return x
 
-def random_planar_angle_pdf(maximum_planar_angle, dim):
-    """Return a random planar angle using rejection sampling."""
-    # We apply the log function just to prevent the floats from
-    # underflowing.
-    box_height = (dim-2)*log(sin(min(maximum_planar_angle, pi/2)))
-    while True:
-        theta = maximum_planar_angle*random()
-        f = box_height + log(random())
-        if f < (dim-2)*log(sin(theta)):
-            return theta
-
 def random_on_disk(axis, planar_angle):
     """Return a random vector uniformly distributed on the periphery of a
 disk."""
@@ -64,4 +53,13 @@ def random_on_cap(axis, maximum_planar_angle):
 cap. The random planar angle is generated using rejection sampling.
 
     """
-    return random_on_disk(axis, random_planar_angle_pdf(maximum_planar_angle, axis.size))
+    # We apply the log function just to prevent the floats from
+    # underflowing.
+    dim = axis.size
+    box_height = (dim-2)*log(sin(min(maximum_planar_angle, pi/2)))
+    while True:
+        theta = maximum_planar_angle*random()
+        f = box_height + log(random())
+        if f < (dim-2)*log(sin(theta)):
+            break
+    return random_on_disk(axis, theta)