Library · Geometric Probability · Chapter 42

Random walk from the centre of a unit square and cube

Revised Report an error

Problem 42.1

You start at the centre of the unit square and pick a random direction to move in, with all directions equally likely. You move along this direction until you reach a point on the perimeter of the square. On average, how far can you expect to have travelled?

Problem 42.2

You start at the centre of the unit cube. You pick a random direction uniformly on the sphere and move in that direction until reaching the surface of the cube. On average, how far can you expect to have travelled?

Solution, part (a): the square. Place the square with corners at (0,0)(0, 0), (1,0)(1, 0), (1,1)(1, 1), (0,1)(0, 1). By symmetry the mean length over all directions equals the mean over the triangle with vertices (1/2,1/2)(1/2, 1/2), (1,1/2)(1, 1/2), (1,1)(1, 1). Pick a direction θ∈[0,π/4]\theta \in [0, \pi/4]; the ray hits the right edge at distance d(θ)  =  12cos⁡θ.d(\theta) \;=\; \frac{1}{2 \cos \theta}. Weighting by the fraction of angles in the fundamental sector, 4/π4/\pi per radian of θ\theta, E[d]  =  4π∫0π/412cos⁡θ dθ  =  2π∫0π/4sec⁡θ dθ  =  2π ln⁡ ⁣(sec⁡θ+tan⁡θ)∣0π/4.\mathbb{E}[d] \;=\; \frac{4}{\pi} \int_0^{\pi/4} \frac{1}{2 \cos \theta} \, d\theta \;=\; \frac{2}{\pi} \int_0^{\pi/4} \sec \theta \, d\theta \;=\; \frac{2}{\pi} \, \ln\!\bigl(\sec \theta + \tan \theta\bigr) \Big|_0^{\pi/4}. At θ=π/4\theta = \pi/4 the bracketed quantity is 2+1\sqrt 2 + 1; at θ=0\theta = 0 it is 11. Therefore E[dsquare]  =  2π ln⁡ ⁣(2+1)  =  ln⁡(3+22)π  ≈  0.5611.\boxed{\mathbb{E}[d_{\text{square}}] \;=\; \frac{2}{\pi} \, \ln\!\bigl(\sqrt 2 + 1\bigr) \;=\; \frac{\ln(3 + 2 \sqrt 2)}{\pi} \;\approx\; 0.5611.} ■

The integral of sec⁡θ\sec \theta admits four classical derivations worth recording.

Method 1. Multiply the integrand by (sec⁡x+tan⁡x)/(sec⁡x+tan⁡x)=1(\sec x + \tan x)/(\sec x + \tan x) = 1. The numerator becomes sec⁡2x+sec⁡xtan⁡x\sec^2 x + \sec x \tan x, which is exactly the derivative of sec⁡x+tan⁡x\sec x + \tan x. Setting u=sec⁡x+tan⁡xu = \sec x + \tan x reduces the integral to ∫du/u=ln⁡∣u∣+C=ln⁡∣sec⁡x+tan⁡x∣+C\int du/u = \ln|u| + C = \ln|\sec x + \tan x| + C.

Method 2 (Weierstrass substitution). With t=tan⁡(x/2)t = \tan(x/2), the half-angle formulas give cos⁡x=(1−t2)/(1+t2)\cos x = (1 - t^2)/(1 + t^2) and dx=2 dt/(1+t2)dx = 2 \, dt/(1 + t^2), so ∫sec⁡x dx  =  ∫21−t2 dt  =  ln⁡ ⁣∣1+t1−t∣+C  =  ln⁡ ⁣∣tan⁡ ⁣(π4+x2)∣+C,\int \sec x \, dx \;=\; \int \frac{2}{1 - t^2} \, dt \;=\; \ln \!\left|\frac{1 + t}{1 - t}\right| + C \;=\; \ln \!\left|\tan\!\bigl(\tfrac{\pi}{4} + \tfrac{x}{2}\bigr)\right| + C, the last step by the tangent addition formula.

Method 3 (complex exponentials). With cos⁡x=(eix+e−ix)/2\cos x = (e^{ix} + e^{-ix})/2 and the substitution u=eixu = e^{ix}, ∫sec⁡x dx  =  2i∫duu2+1  =  −2i arctan⁡(eix)+C,\int \sec x \, dx \;=\; \frac{2}{i} \int \frac{du}{u^2 + 1} \;=\; -2 i \, \arctan(e^{ix}) + C, which, on the real line, reduces to ln⁡∣sec⁡x+tan⁡x∣+C\ln|\sec x + \tan x| + C.

Method 4 (hyperbolic). With x=itx = i t, cos⁡(it)=cosh⁡t\cos(i t) = \cosh t, so ∫sec⁡x dx  =  i∫sech⁡t dt  =  2iarctan⁡ ⁣(tanh⁡(t/2))+C,\int \sec x \, dx \;=\; i \int \operatorname{sech} t \, dt \;=\; 2 i \arctan\!\bigl(\tanh(t/2)\bigr) + C, again equivalent to ln⁡∣sec⁡x+tan⁡x∣+C\ln|\sec x + \tan x| + C after substituting back.

Solution, part (b): the cube. Place the cube with corners at (0,0,0)(0, 0, 0) and (1,1,1)(1, 1, 1). A random direction on the sphere is v⃗  =  (sin⁡φcos⁡θ, sin⁡φsin⁡θ, cos⁡φ),\vec v \;=\; (\sin \varphi \cos \theta, \, \sin \varphi \sin \theta, \, \cos \varphi), with uniform measure (4π)−1sin⁡φ dφ dθ(4\pi)^{-1} \sin \varphi \, d\varphi \, d\theta. From the centre the distance to the boundary is d  =  12 m,m  =  max⁡(∣sin⁡φcos⁡θ∣, ∣sin⁡φsin⁡θ∣, ∣cos⁡φ∣).d \;=\; \frac{1}{2 \, m}, \qquad m \;=\; \max\bigl(|\sin \varphi \cos \theta|, \, |\sin \varphi \sin \theta|, \, |\cos \varphi|\bigr).

The magnitude m=max⁡(∣x∣,∣y∣,∣z∣)m = \max(|x|, |y|, |z|) is unchanged by the 4848 symmetries of the cube, so it suffices to average over a single fundamental region: the directions in the first octant whose xx-component is largest in magnitude. There are 2424 congruent such regions (eight octants, each subdivided by which of the three coordinates is largest), each of solid angle 4π/244\pi/24. In it, θ∈[0,π4],φ∈[arctan⁡(sec⁡θ), π2].\theta \in \left[0, \tfrac{\pi}{4}\right], \qquad \varphi \in \left[\arctan(\sec \theta), \, \tfrac{\pi}{2}\right]. Here d=1/(2sin⁡φcos⁡θ)d = 1/(2 \sin \varphi \cos \theta), and the sin⁡φ\sin \varphi in the spherical measure sin⁡φ dφ dθ\sin \varphi \, d\varphi \, d\theta cancels the sin⁡φ\sin \varphi in the denominator of dd. Averaging over the region multiplies the integral by 24/(4π)24/(4\pi); together with the factor 12\tfrac12 in d=1/(2m)d = 1/(2m) this gives the prefactor 3/π3/\pi: E[d]  =  3π∫0π/4π2−arctan⁡(sec⁡θ)cos⁡θ dθ  =  3π∫0π/4arctan⁡(cos⁡θ)cos⁡θ dθ,\mathbb{E}[d] \;=\; \frac{3}{\pi} \int_0^{\pi/4} \frac{\tfrac{\pi}{2} - \arctan(\sec \theta)}{\cos \theta} \, d\theta \;=\; \frac{3}{\pi} \int_0^{\pi/4} \frac{\arctan(\cos \theta)}{\cos \theta} \, d\theta, where the last step uses arctan⁡(x)+arctan⁡(1/x)=π/2\arctan(x) + \arctan(1/x) = \pi/2 for x>0x > 0. The integral does not collapse to elementary constants. Numerically, ∫0π/4arctan⁡(cos⁡θ)cos⁡θ dθ  ≈  0.63951,\int_0^{\pi/4} \frac{\arctan(\cos \theta)}{\cos \theta} \, d\theta \;\approx\; 0.63951, giving E[dcube]  ≈  0.6107.■\boxed{\mathbb{E}[d_{\text{cube}}] \;\approx\; 0.6107.} \qedhere

The expected distance rises from 0.5610.561 (22D) to 0.6110.611 (33D) by just under 9%9\%. An extra dimension opens longer body-diagonal directions (up to 3/2≈0.866\sqrt 3 / 2 \approx 0.866), but the cube’s six faces cut most rays off quickly, so the uniform-direction average lifts only modestly above the inradius 12\tfrac12.

import numpy as np
np.random.seed(0); n = 10**6

# 2D: uniform theta, distance from centre of unit square to boundary.
theta = np.random.uniform(0, 2*np.pi, n)
dx, dy = np.cos(theta), np.sin(theta)
t = np.minimum(
    np.minimum(np.where(dx>0, 0.5/dx, np.inf), np.where(dx<0, -0.5/dx, np.inf)),
    np.minimum(np.where(dy>0, 0.5/dy, np.inf), np.where(dy<0, -0.5/dy, np.inf)))
exact_2d = (2/np.pi) * np.log(1 + np.sqrt(2))
print(f"2D sim: {t.mean():.5f}   exact: {exact_2d:.5f}")
# 2D sim: 0.56113   exact: 0.56110

# 3D: uniform direction on sphere, distance from centre of unit cube to boundary.
theta = np.random.uniform(0, 2*np.pi, n)
u = np.random.uniform(-1, 1, n)
s = np.sqrt(1 - u*u)
dx, dy, dz = s*np.cos(theta), s*np.sin(theta), u
t = np.minimum.reduce([
    np.where(dx>0, 0.5/dx, np.inf), np.where(dx<0, -0.5/dx, np.inf),
    np.where(dy>0, 0.5/dy, np.inf), np.where(dy<0, -0.5/dy, np.inf),
    np.where(dz>0, 0.5/dz, np.inf), np.where(dz<0, -0.5/dz, np.inf)])
print(f"3D sim: {t.mean():.5f}   integral target: 0.61069")
# 3D sim: 0.61070
Report an error on this page

Reports are stored by Netlify. See the privacy note.