All projects

Mathematics

Buffon's Needle

An interactive Monte Carlo simulation of Buffon's needle experiment for estimating π. Drop needles randomly on parallel lines and observe how the probability of crossings converges to the theoretical value, providing a beautiful geometric method for approximating π through statistical sampling.

  • Monte Carlo
  • Probability

Adjust the needle length, simulation speed, and other parameters to explore how Buffon's needle experiment estimates π. Watch the convergence as more needles are dropped and the estimate approaches the true value of π.

© Hosein Gholami

Experiment

The formula needs L ≤ D. Changing L starts a new estimate.
Older needles leave the picture but still count.
Off: count only (fastest).
Drops N0
Crossings H0
Estimate—
95% CI ±—
Abs. error—

Convergence

Angle histogram

What is Buffon's needle problem?

Buffon's needle problem, posed by Georges-Louis Leclerc, Comte de Buffon in 1777, asks: "What is the probability that a needle of length L, dropped at random on a plane ruled with parallel lines distance D apart, will cross one of the lines?" The answer provides a remarkable connection between geometry and probability, offering a method to estimate π through statistical sampling.

The mathematical solution

For a needle of length LL dropped on parallel lines spaced distance DD apart, the probability of crossing a line is:

P=2LπDP = \frac{2L}{\pi D}

This formula assumes L≤DL \le D (the needle is not longer than the line spacing). Rearranging to solve for π:

π=2LP⋅D\pi = \frac{2L}{P \cdot D}

Monte Carlo estimation

In practice, we don't know the theoretical probability PP. Instead, we estimate it by dropping NN needles and counting the number of crossings HH. The empirical probability is P^=H/N\hat{P} = H/N, giving us the Monte Carlo estimate:

π≈2L⋅NH⋅D\pi \approx \frac{2L \cdot N}{H \cdot D}

Derivation of the probability formula

The key insight is that we need to consider both the position and orientation of the needle. Let xx be the distance from the needle's center to the nearest line, and θ\theta be the angle between the needle and the direction of the lines (so the needle reaches L2sin⁡θ\tfrac{L}{2}\sin\theta towards the nearest line).

The needle crosses a line if and only if:

x≤L2sin⁡θx \leq \frac{L}{2} \sin\theta

Since xx is uniformly distributed in [0,D/2][0, D/2] and θ\theta is uniformly distributed in [0,π/2][0, \pi/2], the probability is:

P=2π∫0π/2Lsin⁡θD dθ=2LπDP = \frac{2}{\pi} \int_0^{\pi/2} \frac{L \sin\theta}{D} \, d\theta = \frac{2L}{\pi D}

Convergence and accuracy

The Monte Carlo method converges to the true value of π as the number of trials increases. The standard error of the estimate is approximately:

SE≈πN1−PP,P=2LπD\text{SE} \approx \frac{\pi}{\sqrt{N}} \sqrt{\frac{1-P}{P}}, \qquad P = \frac{2L}{\pi D}

This follows from Var⁡P^=P(1−P)/N\operatorname{Var}\hat P = P(1-P)/N and ∣dπ/dP∣=π/P|d\pi/dP| = \pi/P. The simulation shades the 95% interval π^±1.96 SE\hat\pi \pm 1.96\,\text{SE}. The error shrinks as 1/N1/\sqrt{N}, which is typical for Monte Carlo methods. The convergence is slow but steady, making it a beautiful demonstration of statistical sampling.

Historical significance

Buffon's needle problem is historically significant as one of the earliest examples of geometric probability. It predates the axiomatic foundations of probability theory by two centuries and demonstrates how geometric intuition can lead to profound mathematical insights. The problem has been extended to various shapes and configurations, making it a cornerstone of geometric probability theory.

Practical considerations

  • Needle length constraint: The formula assumes L≤DL \le D for simplicity.
  • Random sampling: True randomness is crucial for accurate results.
  • Convergence rate: Expect slow convergence requiring many trials for high precision.
  • Visualization: The simulation helps understand the geometric nature of the problem.

Extensions and variations

The problem has been extended to various shapes (Buffon's noodle), different line configurations, and higher dimensions. Each variation provides new insights into the relationship between geometry and probability, making Buffon's needle a fundamental example in geometric probability theory.