Intereting Posts

A trigonometric identity for special angles
Evaluate $\int \cos^3 x\;\sin^2 xdx$
Derivative of Associated Legendre polynomials at $x = \pm 1$
coupon collector problem with groups
Prove that one of $n$ consecutive integers must be divisible by $n$
Can anyone tell me why the arclength integral is an uppersemicontinuous function on the set of continuously differentiable real-valued functions?
Probability of Various Combinations of Weather
Formula for working out the number of dice combinations resulting in a given value
Probability question (Birthday problem)
Does $\sin(x+iy) = x+iy$ have infinitely many solutions?
If $x_n\leq y_n$ then $\lim x_n\leq \lim y_n$
Evaluating $\lim_{n\to \infty}\frac1{2n}\log\left({2n \choose n}\right)$
$ \int_{0}^{ \infty} \int_{0}^{ \infty} \frac { e^{-(x+y)}}{x+y} dx dy $
Fermat numbers are coprime
Metric triangle inequality $d_2(x,y):= \frac{d(x,y)}{d(x,y)+1}$

I have a sphere of radius $R_{s}$, and I would like to pick random points in its volume with uniform probability. How can I do so while preventing any sort of clustering around poles or the center of the sphere?

Since I’m unable to answer my own question, here’s another solution:

Using the strategy suggested by Wolfram MathWorld for picking points on the surface of a sphere: Let $\theta$ be randomly distributed real numbers over the interval $[0,2\pi]$, let $\phi=\arccos(2v−1)$ where $v$ is a random real number over the interval $[0,1]$, and let $r=R_s (\mathrm{rand}(0,1))^\frac13$. Converting from spherical coordinates, a random point in $(x,y,z)$ inside the sphere would therefore be: $((r\cos(\theta)\sin(\phi)),(r\sin(\theta)\sin(\phi)),(r\cos(\phi)))$.

- Can we define the normal set without $G$ being a group?
- How to prove that $\frac{r}{R}+1=\cos A+\cos B+\cos C$?
- line equidistant from two sets in the plane
- Distance between a point and a m-dimensional space in n-dimensional space ($m<n$)
- Formal proof for detection of intersections for constrained segments
- Find out the angle of <ABC

A quick test with a few thousand points in the unit sphere appears to show no clustering. However, I’d appreciate any feedback if someone sees a problem with this approach.

- Algorithm to get the maximum size of n squares that fit into a rectangle with a given width and height
- Convex combination
- How to calculate the coordinates of orthocentre.!!
- Determinant form of equation, 3 variables, third order (nomogram)
- Given vectors $u,v, i$, find vector $w$ such that $i$ is incenter of triangle $$
- Is there a geometrical definition of a tangent line?
- who first defined a tangent to a circle as a line meeting it only once?
- change of basis and inner product in non orthogonal basis
- The shape of Pringles potato chip
- Find the point in a triangle minimizing the sum of distances to the vertices

Let’s say your sphere is centered at the origin $(0,0,0)$.

For the distance $D$ from the origin of your random pointpoint, note that you want $P(D \le r) = \left(\frac{r}{R_s}\right)^3$. Thus if $U$ is uniformly distributed between 0 and 1, taking $D = R_s U^{1/3}$ will do the trick.

For the direction, a useful fact is that if $X_1, X_2, X_3$ are independent normal random variables with mean 0 and variance 1, then

$$\frac{1}{\sqrt{X_1^2 + X_2^2 + X_3^2}} (X_1, X_2, X_3)$$

is uniformly distributed on (the surface of) the unit sphere. You can generate normal random variables from uniform ones in various ways; the Box-Muller algorithm is a nice simple approach.

So if you choose $U$ uniformly distributed between 0 and 1, and $X_1, X_2, X_3$ iid standard normal and independent of $U$, then

$$\frac{R_s U^{1/3}}{\sqrt{X_1^2 + X_2^2 + X_3^2}} (X_1, X_2, X_3)$$

would produce a uniformly distributed point inside the ball of radius $R_s$.

An alternative method in $3$ dimensions:

Step 1: Take $x, y, $ and $z$ each uniform on $[-r_s, r_s]$.

Step 2: If $x^2+y^2+z^2\leq r_s^2$, stop. If not, throw them away and return to step $1$.

Your success probability each time is given by the volume of the sphere over the volume of the cube, which is about $0.52$. So you’ll require slightly more than $2$ samples on average.

If you’re in higher dimensions, this is not a very efficient process at all, because in a large number of dimensions a random point from the cube is probably not in the sphere (so you’ll have to take many points before you get a success). In that case a modified version of Nate’s algorithm would be the way to go.

Nate and Kevin already answered the two I knew. Recalling this and this, I think that another way to generate a uniform distribution over the sphere surface would be to generate a uniform distribution over the vertical cylinder enclosing the sphere, and then project horizontally.

That is, generate $z \sim U[-R,R]$, $\theta \sim U[0,2\pi]$, and then $x=\sqrt{R^2-z^2} \cos(\theta)$, $y=\sqrt{R^2-z^2} \sin(\theta)$. This (if I’m not mistaken) gives a uniform distribution over the sphere surface. Then, apply Nate’s recipe to get a uniform distribution over the sphere volume.

This method is a little simpler (and more efficient) than the accepted answer, though it’s not generalizable to other dimensions.

I just want to add a small derivation to leonbloy’s answer, which uses calculus instead of geometrical intuition. Changing from cartesian $(x,y,z)$ to spherical $(r,\theta,\phi)$ coordinates, we have for the volume element

$$dx dy dz =r^2 \sin \theta ~ dr d\theta d\phi$$

The coordinates $(r,\theta,\phi)$ don’t work for a uniform distribution because we still have a non-constant factor in front of $dr d\theta d\phi$ (see “EDIT” at the bottom, if you do not see why they don’t work). Therefore we introduce

$$u=-\cos \theta \Rightarrow du= \sin \theta d\theta$$

$$\lambda=r^3/R^3 \Rightarrow d \lambda=\frac{3}{R^3}r^2dr$$

with which we obtain an expression with a constant pre-factor

$$dx dy dz= \frac{R^3}{3} d\lambda du d\phi$$

The range of our variables is $\lambda \in [0,1], ~u \in [-1,1], \phi \in [0, 2\pi) $. Choosing those numbers uniformly we get cartesian coordinates

$$

\begin{align}

x&=r \sin(\theta) \cos (\phi) =&R \lambda^{1/3} \sqrt{1-u^2}\cos(\phi)\\

y&=r \sin(\theta) \sin (\phi) =&R \lambda^{1/3} \sqrt{1-u^2}\sin(\phi) \\

z&=r \cos (\theta)=&R \lambda^{1/3} u

\end{align}

$$

EDIT: I want to add an argument why we want a constant prefactor in front of $d\lambda du d\phi$.

Consider the one dimensional case (uniform distribution of points on the line $[0,L]$). For $0<x<L$ the probability to find a point in $(x,x+dx)$ is $P(x)dx$. Since we assume a uniform probability, $P(x)$ has to be $P(x)=1/L$, and hence the probability $P(x)dx=dx/L$ is directly proportional to the volume element $dV=dx$.

Now consider we have a variable $y$, for which we do not know the probability density $Q(y)$ but we know that the volume element is $dV=dx=c dy$ with some constant $c$. Furthermore, we know that $Q(y)dy$ has to be $P(x)dx$ (by definition of probability density). Hence $Q(y)=P(x)dx/dy=c$.

In summary we have shown:

“Variable $y$ is uniformly distributed” $\Leftrightarrow$ “The volume element is $dV=c dy$ for some constant $c$. (For the correct normalization of the probability density the value of $c$ is not arbitrary)

- Does the proof of Bolzano-Weierstrass theorem require axiom of choice?
- Why is this sequence of functions not uniformly convergent?
- Is the degree of an infinite algebraic extensions always countable?
- Limit of function at infinity: $ \lim_{n\to \infty} \frac{a^n-b^n}{a^n+b^n} $
- Pseudocompactness in the $m$-topology in $C(X)$
- Cesaro Means convergence
- Logic and number theory books
- Proving that $\lim\limits_{x \to 0}\frac{e^x-1}{x} = 1$
- Metric on an open subset of $\mathbb{R}^d$ and Christoffel symbol of the second kind
- Finding the derivative of $x^x$
- advanced calculus, differentiable and limit problem
- If $n^c\in\mathbb N$ for every $n\in\mathbb N$, then $c$ is a non-negative integer?
- For which categories we can solve $\text{Aut}(X) \cong G$ for every group $G$?
- About the slack variable for hinge-loss SVM
- This recurrence relation will evaluate to?