Sampling points uniformly inside a sphere; marginal distribution of the dimensions

354 Views Asked by At

I was asked a question on how to uniform sample points inside a sphere, and what is the marginal distribution of one dimension.

The most obvious solution that came to me was rejection sampling. Simply consider a hypercube around the sphere. Say the radius of the sphere is $R$, hence the side lengths of the cube is $2R$. Then we can sample $X,Y,Z \in U(-R, R)$.

We reject all the points such that $\sqrt{X^2+Y^2+Z^2} > R$, and the remaining points that we accept should be uniformly distributed within the sphere.

I'm not sure if there's a better approach analogous to the gaussian sampling method for points on the surface of a sphere. But anyways, the second question asked me what is the marginal distribution of each dimension.

At first, I thought isn't the marginal distribution simply $U(-R, R)$, but then I realized that this is incorrect. I think the distribution we're looking for is a conditional distribution given the point is validly inside the sphere.

While we sampled $X,Y,Z$ from a uniform distribution, we rejected samples as well, and the accepted sample's dimensions are no longer uniformly distributed. This is easier to see in 2-D, where if you consider a circle, where center is at $X=Y=0$, we will see that the $X,Y$ values close to the center will have a higher frequency of occurring, because the other dimension isn't as constrained. For example, consider $X=0$, any value of $Y \sim U(-R,R)$ will be inside the circle. But if say $X = 0.5$, then $Y$'s possible values are reduced to the interval $[-\sqrt{R^2 - 0.5^2}, \sqrt{R^2 - 0.5^2}]$.

So my inclination now is that each dimension is some type of symmetrically distributed pdf about the center, with the peak pdf value occurring at the center. I want to say that it's a gaussian distribution, but the gaussian distribution extends to $\pm \infty$, whereas this pdf we're looking for is bounded by $\pm R$.

As somewhat of an aside, and maybe relevant to solving this question (?), is there a way to figure out the joint pdf of $X,Y,Z$?