Distance between two uniform points in a three-dimensional ball (source code)

= Distance between two uniform points in a three-dimensional ball
{title2=$f_R(r)=3r^2/R^3-9r^3/(4R^4)+3r^5/(16R^6)$}

For two <independent random variables> taking values in a three-dimensional <ball> with constant volume <probability density>, the density of their distance is the displayed expression for $0\leq r\leq2R$, and zero otherwise. Both <independence> and the common radius $R>0$ are essential. To derive it, put $u=|\mathbf r_1|$, $v=|\mathbf r_2|$ and integrate the product volume <differential form> over orientations. The <law of cosines> gives the angular <Jacobian determinant> $v/(ur)$, leaving $f_R(r)=9r\int uv\,du\,dv/(2R^6)$ over $0\leq u,v\leq R$, $|u-v|\leq r\leq u+v$. With $x=u+v$, $y=u-v$, the integrand becomes $(x^2-y^2)\,dx\,dy/8$. Direct integration gives $\int uv\,du\,dv=2R^3r/3-R^2r^2/2+r^4/24$. An independent geometric derivation uses the overlap volume of two radius-$R$ balls displaced by $r$, namely $\pi(4R+r)(2R-r)^2/12$, multiplied by $4\pi r^2$ and divided by the square of $4\pi R^3/3$. The density integrates to one and has mean $36R/35$.