# Thread: mean nearest neighbor distance in 3d

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.

3. I think you'll need to start by carefully defining what you mean by randomly generated. To see why this matters, consider this: http://demonstrations.wolfram.com/RandomChordParadox/  4. Originally Posted by MagiMaster
I think you'll need to start by carefully defining what you mean by randomly generated. To see why this matters, consider this: http://demonstrations.wolfram.com/RandomChordParadox/
Interesting. I think the 2nd option listed in the demo, where a point on the circle is randomly selected, then another point on the circle is randomly selected, and then the two points are joined by a chord corresponds to what most people would intuitively consider to be random in that situation, IMO.

For our random distribution of n points in a 3-dimensional Euclidean volume, let us 1st pick a random value for the x-coordinate of the 1st point between the limits allowed by the region in question (cube, sphere, general volume, etc.), then for the y-coordinate, than z, then the same for all the other n-1 points.

I still can't think of a better formula than (volume/n)^1/3.   5. Modest at

http://hypography.com/forums/physics...stance-3d.html

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)

where
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

integrating:

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

normalizing:

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. 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

people.hofstra.edu/stefan_waner/RealWorld/integral/integral.html

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   Bookmarks
 Posting Permissions
 You may not post new threads You may not post replies You may not post attachments You may not edit your posts   BB code is On Smilies are On [IMG] code is On [VIDEO] code is On HTML code is Off Trackbacks are Off Pingbacks are Off Refbacks are On Terms of Use Agreement