Return a uniform distribution of n-dimensional vectors inside an
n-sphere of radius r.
(with-monad state-m
(defn n-sphere
"Return a uniform distribution of n-dimensional vectors inside an
n-sphere of radius r."
[n r]
(let [box-dist (sample n (interval (- r) r))
sq #(* % %)
r-sq (sq r)
vec-sq #(apply + (map sq %))
sphere-dist (reject #(> (vec-sq %) r-sq) box-dist)
as-vectors (m-lift 1 vec)]
(as-vectors sphere-dist))))
Comments top
No comments for n-sphere. Log in to add a comment.