1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Mean nearest neighbor distance in 3d

  1. Nov 24, 2009 #1
    Hi. In 3 dimensional Euclidean space with the usual metric, d=[(delta x)^2+(delta y)^2+(delta z)^2]^1/2, I'm trying to figure out the average distance between nearest neighbors in a randomly distributed sample of particles. My best initial guess for the average distance from any given particle to its nearest neighbor is d_nearest neighbor_mean=(volume/n)^1/3 where n particles are randomly distributed in a 3 dimensional volume.

    The question originated when I wondered what was the average distance between stars in the solar neighborhood. atlasoftheuniverse.com gives 35 stars (including the Sun) within 12.5 light-years, and the above formula yields 6.16 ly as the avg distance from any given star to its closest neighbor. This seemed a little high to me, since the distance from the Sun to its nearest neighbor (Proxima Centauri) is 4.4 ly. But perhaps the Sun has a closer-than-avg nearest neighbor, since, after all, the distribution should be very close to random. Let us assume that the stars are randomly distributed.

    I originally thought it would be easy to figure this out, but after trying unsuccessfully for an hour to work out a better formula, then another hour trying to google one, I gave up. Thanks in advance :)
  2. jcsd
  3. Nov 24, 2009 #2


    Staff: Mentor

    If there are 35 stars within 12.5 LY of the sun, and Proxima Centaurii is the closest at 4.4 LY, it's not at all surprising that you got a mean distance of 6.16 LY. All of these stars are distributed between 4.4 LY and 12.5 LY, so if there are distributed uniformly or normally, the mean distance would certainly be somewhere between the extreme values.
  4. Nov 25, 2009 #3
    interesting problem. Did you make this up on your own, or is it a textbook problem?

    Here's an solution that gives you an average distance of 3.8 ly.

    Let's say that each piece of volume dV has an equal probability of containing a star. And let n be the number of stars in the total volume of interest V, so that the density function is just (n/V). And the average number of stars in a chosen volume v about some center point is just v(n/V). Then you're looking for the volume v at which the expected number of stars in the volume v is exactly 1. This is true when v = (V/n). Solving for r (v = (4/3)pi*r^3 ), then

    r = [ (3V) / (4*pi*n) ] ^ (1/3)

    I found V and n from your numbers (35 stars within 12.5 ly, so n=35, v = (4/3)*pi*12.5^3 =8181 ly^3 ), and then calculated r to be 3.8. So you would expect to find your first star within 3.8 ly of any chosen point, though the actual distance will vary about 3.8 ly.
  5. Nov 27, 2009 #4
    Modest at


    was helpful in pointing me to this link:

    http://books.google.com/books?id=hp...n a random distribution of particles"&f=false

    And now I need to integrate:

    integral of x^3 exp(-a x^3) dx, with a = constant,

    but I couldn't. Hopefully, it's an easy integral and and someone will figure it out.

    In a 3-dimensional random distribution, the basic idea for finding the average distance from any given particle to its nearest neighbor begins with:

    P(r)dr = [1 - integral from 0 to r of P(r)dr][4 pi r^2 pho dr] (1)

    pho = average number of particles/unit volume
    P(r) dr = the probability of a particle's nearest neighbor occurring in the interval [r,r+dr]
    integral from 0 to r of P(r) dr = probablity that an arbitrary particle's nearest neighbor lies within a distance r of the particle
    1 - integral from 0 to r of P(r) dr = the probability that the nearest neighbor is no closer than r.

    differentiating & separating eq. 1:

    dP/P = [2/r - 4 pi rho r^2] dr


    P = [constant] r^2 exp(- [4/3] pi rho r^3)


    1 = integral from 0 to infinity of P(r) dr
    1 = [constant] integral from 0 to infinity of r^2 exp(-[4/3] pi rho r^3) dr
    1 = [constant] [-[1/(4 pi rho)] exp(-[4/3] pi rho r^3)] evlauated from 0 to infinity

    gives the constant = 4 pi rho and P(r) = 4 pi rho r^2 exp(-[4/3] pi rho r^3)

    The average distance from any given particle to its nearest neighbor in 3 dimensions is then the expectation value of r:

    <r> = integral from 0 to infinity of r P(r) dr
    <r> = [4 pi rho] [integral from 0 to infinity of r^3 exp(-[4/3] pi rho r^3) dr]

    I was unable to do the last integral, but I'm sure someone can :)
  6. Nov 27, 2009 #5


    User Avatar

    Staff: Mentor

    I wonder what it means "35 stars in the 12.5 ly radius". It means either 35th star is 12.5 ly from us, or 36th start is at this distance - or anything in between.
  7. Nov 27, 2009 #6
    I am going to look at the 2D derivation the Modest showed us, ASAP.

    Until then, note that my previous solution is probably very slightly off, though I'm not yet sure why. By my reasoning, for the 2D nearest neighbor distance problem I would say that we are looking for the value of r for which rho*(pi*r^2) =1.0, aka <r> = 1/ (pi*rho)^.5 , where rho is the average density. This is 0.564/(rho^.5), remarkably close to the given 2D solution of .5/(rho^.5). Interesting!

    When we solve the 3D problem, we can see how close my answer is (I said <r> = [(3/4)*(1/pi)*(1/rho)]^1/3 , where rho is the 3D avg density.....this actually gives <r> = 0.621/(rho^1/3))

    It will be interesting to see if your integral gives something close to 0.621 / (rho^1/3)
  8. Nov 28, 2009 #7
    since what we really want is the average distance to the nearest star system, and atlasoftheuniverse.com reports 23 star systems within 12.5 ly (35 stars but 3 trinaries, 6 binaries, and 14 singles), we have:

    rho = 23/([4/3]pi 12.5^3)
    rho = 0.0028113 star systems/cubic light-year

    rho is only an estimate since some of the star systems near the outer edge of the volume (of 12.5 ly radius) might have nearest neighbors outside the volume and some star systems just outside the volume might have nearest neighbors inside.

    since the integral of x^3 exp(-a x^3)dx doesn't seem to be integrable, I used

    http://people.hofstra.edu/stefan_waner/RealWorld/integral/integral.html [Broken]

    to numerically integrate:

    the integral from 0 to infinity of 0.035328(x^3)(e^(-0.011776(x^3)))dx = 3.93 light years

    as the average distance from an arbitrary star system in the solar neighborhood to its nearest nighbor :)
    Last edited by a moderator: May 4, 2017
  9. Nov 28, 2009 #8
    Good stuff.

    Based on the new approach of star systems, which gives rho = 0.002811, my equation gives 4.396 ly.

    This is extremely close to 4.4 ly, the value you gave as the distance from our sun to Proxima Centauri. This is probably nothing more than statistical coincidence.

    Do you think that for suitably large volumes and # of stars, my approach is correct?

    Basically all I am saying mathematically is that if we model the position of stars as roughly independent (which I believe your model also does), then the number of stars in a volume should be proportional to that volume. I find <r> geometrically using the volume at which the expected number of stars equals exactly 1.0.
  10. Nov 28, 2009 #9
    I'm not sure but I think the problem with your approach is:
    1. There are 2 star systems within your control volume; the system at the center and the nearest system.
    2. your volume as stated doesn't need to be centered on an arbitrary star system, but can be centered at any point. Perhaps you are finding the minimun volume within the region that contains 1 star system.
  11. Nov 28, 2009 #10
    aswoods at


    helpfully pointed out that Gradshteyn and Ryzhik 3.381.10, and Wolfram Alpha agree that

    the integral from 0 to infinity of x^3 e^(-ax^3)dx = 1/3 gamma(4/3) a^(-4/3)

    so the mean nearest neighbor distance in 3d is:

    <r> = [4 pi rho] integral from 0 to infinity r^3 e^(-[4/3] pi rho r^3) dr
    <r> = 1/3 gamma(1/3) ([4/3] pi)^(-1/3) rho^(-1/3)
    <r> = 0.55396 rho^(-1/3)
    <r> = 3.93 light-years for the 23 star systems within 12.5 ly :)
  12. Nov 28, 2009 #11
    or the mean minimum volume within the region that contains at least 1 star system
  13. Nov 29, 2009 #12

    I guess a more correct derivation of expected distance to nearest star should imply integration up to a formal radius Rmax, regarding increased density between r and Rmax
    due to no star found up to that r. So density reaches infinity at Rmax, for instance. I.e the same derivation procedure, but regarding this theoretically increased density in formuas.
    And first afterwards letting Rmax reach infinity. Likely it doesnt change end result, but
    theoretically that compression during integration should be regarded.

    I may return with a complete derivation regarding this. :yuck:
  14. Dec 3, 2009 #13
    Here I am again. (The "LaTex" symbol routine for some reason only shows black background to me last time, why I must use simple typing). :mad:

    I assume a formal max radius Rmax instead of directly up to infinity. That also makes the solution easier. But instead of using radius , I use corresponding volume v upp to Vmax.

    Definitions: V = max volume (corresponding to Rmax). v = temporary volume (corresponding to r). N = Number of stars inside V. C = star density = N / V.
    Density outside v is c(v) = C V / (V-v)

    Likelihood a star is not inside v, i.e. in shell between v and V, is (V-v)/V . Implies likelihood all stars outside v is [(V-v)/V] exp CV = Q(v). (Not that easily derived if V was directly put infinite).

    Expected v* for first met star is Integral {v = 0 to V} of [Q(v) c(v)] v dv , where [Q(v) c(v)] is weight factor - who's integral {v= 0 to V} is shown = 1 and therefore already normalized.

    The "Primitive Function" F turns out to be -[v + (V-v)/(CV+1)] [1-(v/V)} exp CV
    and searched v* = F(V) - F(0) = 1 / (C + 1/V)

    Lim v* (V approach infinity) is 1/C according to earlier results here. I.e expected nearest distance 3.8.. LY . :approve:
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Similar Discussions: Mean nearest neighbor distance in 3d