In a recent blog post1 (inspired from reading Peter Shirley’s Ray Tracing in One Weekend) Karthik Karanth derives generating uniform points inside the unit sphere from scratch. This is just a quick note on how this can be improved.

## Uniform points in sphere

If we’re given a black-box implementation of point on unit sphere we could adapt that to an interior point by properly scaling the result. We need a uniform parameterization of the volume: the volume of a sphere is $\frac{4}{3}\pi~r^3$, so the relative cumulative volume is $r^3$ which give a scale factor which is the cube-root of a uniform float.

In a previous post2 I sketched out generating uniform points on sphere as transformed points in disc. Adding the scaling factor to the example code gives:

The uniform_disc function from the previous post is a rejection method with rejection rate of ~0.21. A drop in replacement without rejection would look like:

So a disc transform based method drops the inverse trig op, one pair for forward trig ops without rejection and is trig free for rejection based.

## Uniform points in spherically capped cone

Tossing out another adaption of my previous post: If we take the uniform point on spherical cap and rescale as above we get a uniform point in the volume of the intersection of the unit sphere and conic:

## References and Footnotes

1. Generating Random Points in a Sphere, Karthik Karanth, 2018 link

2. Uniform points on disc, circle, sphere and caps, 2016 local post