Monte Carlo Pi 3D

Darts in a glass cube around a sphere, quasi-random points and Buffon needles on a floor, with a live scoreboard.

Presets

Playback

Estimator and generator

Camera

Layers

Quality

Model check

The science

The idea

Throw random points into the square [-1,1]2. The share that lands inside the unit circle is the area ratio p = π/4, so π ≈ 4 Nin/N. In 3D the unit sphere fills π/6 of the cube, so π ≈ 6 Nin/N.

How fast does it converge?

The count of points inside is binomial, so π-hat has standard error c √(p(1-p)/N) with c = 4 (2D) or 6 (3D): about 1.64/√N in 2D. The error therefore shrinks like N-1/2: one more digit costs 100 times more points. A 95 % interval is ±1.96 standard errors.

Better point sets

Quasi-random Halton points (radical inverses in bases 2, 3, 5) fill the square more evenly and give errors of order (log N)d/N for smooth integrands; the circle's edge is not smooth, so the gain is real but modest. Stratified sampling places one jittered point in each cell of a 32 x 32 grid (8 x 8 x 8 in 3D) and removes the clumping of pure random points. All three generators run side by side so that you can compare them in the same graph.

Buffon's needle

A needle of length L thrown on lines spaced d ≥ L crosses a line with probability 2L/(π d), so π ≈ 2 L N / (d H) after H crossings in N throws. The estimator is noisier than darts because it divides by a count.

Honest simplifications

The pseudo-random numbers come from a small deterministic generator (mulberry32), not a physical source. The Gaussian drawn over the repeated experiments is the central-limit approximation. The Halton and stratified repeats use random shifts or random cells so that their spread can be measured; their errors do not follow the pseudo-random formula. Educational model.

Model checks in this page

(1) the spread of 400 pseudo-random runs matches c √(p(1-p)/N); (2) Halton at N = 4096 beats that standard error; (3) the Buffon crossing probability from numerical integration equals 2L/(π d).

What the 3D scene shows

In dart mode each point of the chosen generator appears inside a glass cube of side 2 (scaled to 0.5 m) that holds the unit sphere: green balls fell inside the sphere, orange ones outside. In 2D mode they fall on the mid-plane with the circle. The scoreboard shows the running estimate and the error of all three generators, the chalkboard the formulas with the live standard error. In Buffon mode the cube is replaced by floor boards spaced d with needles of length L; green needles cross a line. Only the last 14 000 points and 500 needles are drawn; the counts use every point. The gallery was modelled and baked in Blender.

Loading model...
Loading Blender model...
Estimate of pi vs number of points (with 95 % band)
Error vs N (log-log) against 1/sqrt(N)
Distribution of the estimate over 400 runs
Random-walk deviation of the inside count
Made with 🟠 Blender · Three.js