Approximating \( \pi \) using Monte Carlo Simulation

You probably know from your school's math curiculum, that the area of a circle with radius \(1\) is \(\pi\). But what exactly is the value of \(\pi\)? There are a lot of great techniques to approximate this irrational number fast. However, let's stick with the unit circle (i.e. the one with radius \(1\)).

If we cut it in \(4\) equal segments, the area of each will be \(\pi / 4\). Furthermore, each such segment fits in a square with edge length \(1\). Knowing that the area of such a square is \(1\), we could directly infer the area of a circle segment, if we knew what fraction of square and segment overlaps (the segment area will have exactly this value).

In the following, we estimate this fraction, by randomly throwing points into a continuous \(1 \times 1\) square and counting, how many of them hit within the unit circle segment (such a point \((x,y)\) satisfies \(x² + y² \leq 1\)). Multiplying the result with \(4\) - for four segments - we obtain an approximation of the value of \(\pi\).

This technique of conducting a random experiment for a high number of times is called Monte Carlo Simulation. Inspecting the approximation process for some runs, you will notice, that the accuracy of our estimation grows with the number of points we use. Congratulations! You discovered yet another important concept: the law of large numbers.

Controls & Results

Speed Setting

Point Statistics

in unit circle segment \( i = \)
out of circle segment
total number \( a = \)

\( \pi \approx 4 \cdot \frac{i}{a} = \)

Distribution of points in the plane

orange - last point drawn

Approximated value of \( \pi \) per simulation round.