← Iris

Estimate of π

π estimate
Actual π 3.141593
Error

Counts

Total dropped 0
Crossings 0
P(crossing)

Formula

P(cross) = 2L / (πD)
π = 2L / (P · D)
π = 2L·N / (C·D)

Needles

Crossing a line
Not crossing
Convergence curve
Press Drop buttons or let needles fall automatically  ·  Adjust needle length relative to line spacing with the L/D slider  ·  Lower chart shows the running estimate of π converging to the true value

What’s happening

The problem

A floor has parallel lines spaced D apart. A needle of length L (where L ≤ D) is dropped at random. What is the probability that the needle crosses one of the lines?

The solution

Let x be the distance from the needle’s center to the nearest line, and θ be the angle between the needle and the lines. The needle crosses a line when x ≤ (L/2) sin(θ). Since x is uniformly distributed on [0, D/2] and θ on [0, π], we integrate:

P(crossing) = (2 / (Dπ)) ∫₀ᵱ (L/2) sin(θ) dθ
            = (2L) / (πD)
            = 2L / (πD)

Rearranging: π = 2L / (P · D). If we drop N needles and C cross a line, then P ≈ C/N, giving π ≈ 2LN / (CD).

Convergence

The estimate converges as 1/√N, which is typical for Monte Carlo methods. To get one more digit of accuracy, you need roughly 100 times more needles. This is why Monte Carlo estimation of π is a beautiful demonstration but a terrible algorithm — it takes millions of needles to match what a series can compute in seconds.

The long needle case

When L > D, the needle can cross multiple lines. The expected number of crossings is still 2L / (πD) — a remarkable result that follows from linearity of expectation. This generalization is due to Laplace. Adjust the L/D slider above 1.0 to see this regime.

Historical significance

Buffon’s needle (1777) is the oldest problem in geometric probability. It connects a physical experiment to a transcendental number through an integral that depends on nothing but the geometry of randomness. It anticipates Monte Carlo methods by two centuries.