# Probability that distance of two random points within a sphere is less than a constant

Two points are chosen at random within a sphere of radius $r$. How to calculate the probability that the distance of these two points is $< d$?

My first approach was to divide the volume of a sphere with radius d by a sphere with radius r. But it does not seem to work, at least not for $d > r$.

$$P = \frac{ 4/3 \pi d ^3}{ 4/3 \pi r ^ 3 }\tag{?}$$

Any help would be hugely appreciated.

• What is $d$ here? Diameter? If so, then why do you refer to "radius d" and "at least not for for d > r"? – Joel Reyes Noche Aug 28 '15 at 14:13
• d is the distance between the two random points and a constant – Erik Kalkoken Aug 28 '15 at 14:15
• Your first approach will not work when the first point is more than $r-d$ from the centre of the sphere – Henry Aug 28 '15 at 14:21
• It also depends on how you randomize... – Dr Xorile Aug 28 '15 at 16:09
• To clarify lets assume the random function is an equal distribution of points within the sphere. – Erik Kalkoken Aug 28 '15 at 17:18

## 2 Answers

How are you at three-dimensional integrals?
Let the first point be at $(0,0,z)$. There are two spheres: One of radius $r$, centered at the origin, and one of radius $d$, centered at $(0,0,z)$. I would let $r=1$ to remove one letter from your calculations.
The spheres' intersection is symmetric about the $z$ axis, which should help you calculate the volume of the intersection. You rotate the intersection of two semicircles about the $z$ axis.
Once you have $P(z,d)$, you need to calculate the following.
$$P(d)=\frac{\int_0^1 z^2P(z,d)dz}{\int_0^1z^2dz}$$

• Thanks for your fast and comprehensive response. My math is limited, so I have problems to understand the solution. However I have 3 questions: 1) The first point is at random coordinates within the sphere with radius r, not at (0,0,z) 2) I am looking for a solution for different r, so setting it to 1 does not help me. 3) How do you define P(z,d) ?? What I am really looking for, is a function P(r, d), which gives me the %-probability for any r, d > 0. Ideally something that I can calculate in Google sheets. – Erik Kalkoken Aug 28 '15 at 17:16
• @bji74: $P(r,d)=P(1,d/r)$, so it suffices to solve the problem for $r=1$. – joriki Aug 28 '15 at 21:26
• @bji74 (1) Pick the first point. Then change the coordinate system so that it is at (0,0,z). (2) P(r,d) = P(1, d/r) – steven gregory Aug 28 '15 at 22:44
• @StevenGregory: I suspect you intended to ping bji74? – joriki Aug 28 '15 at 22:45

According to MathWorld, the density for $d$ is

$$\frac{3d^2}{r^3}-\frac{9d^3}{4r^4}+\frac{3d^5}{16r^6}\;.$$

Thus the cumulative distribution function that you're looking for is

$$\int_0^d\left(\frac{3d'^2}{r^3}-\frac{9d'^3}{4r^4}+\frac{3d'^5}{16r^6}\right)\mathrm dd'=\left(\frac dr\right)^3-\frac9{16}\left(\frac dr\right)^4+\frac1{32}\left(\frac dr\right)^6\;.$$

Here's a plot.