aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorArun Isaac2021-06-30 14:42:24 +0530
committerArun Isaac2021-06-30 14:42:24 +0530
commitf60a54c593411803a8617c9dcda2f667095d2487 (patch)
tree36dd031ef7f0edf60789f81cd3740da5cecd102a /src
parent7ec6e79a83868fb618b844f7eb46a693c3f021e1 (diff)
downloadnsmc-f60a54c593411803a8617c9dcda2f667095d2487.tar.gz
nsmc-f60a54c593411803a8617c9dcda2f667095d2487.tar.lz
nsmc-f60a54c593411803a8617c9dcda2f667095d2487.zip
Support sampling in sphere.
* src/nd-random.sc (random-vector-in-sphere): New function. * include/nd-random.h (random_vector_in_sphere): Declare it.
Diffstat (limited to 'src')
-rw-r--r--src/nd-random.sc9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/nd-random.sc b/src/nd-random.sc
index 79f6cde..69bb93a 100644
--- a/src/nd-random.sc
+++ b/src/nd-random.sc
@@ -30,6 +30,15 @@
sphere. Write the result to X."
(gsl-ran-dir-nd r (: x size) (: x data)))
+(define (random-vector-in-sphere rng radius x)
+ (void (const gsl-rng*) double gsl-vector*)
+ "Generate a random vector distributed uniformly in a sphere of
+RADIUS. Store the generated vector in X."
+ (random-direction-vector rng x)
+ (gsl-vector-scale x (* radius
+ (pow (gsl-ran-flat rng 0 1)
+ (/ (: x size))))))
+
(define (rotate-from-nth-canonical x orient)
((static void) gsl-vector* (const gsl-vector*))
(let* ((n size-t (: x size))