A Sewing-Circle Method for Estimating Pi
With another “Pi Day” behind us, I thought I’d share a fun method for estimating pi that basically requires a hardwood floor, a bag of sewing needles and plenty of time.
Imagine standing over a hardwood floor. Notice the parallel lines between the boards. Now imagine dropping a single sewing needle onto it. It bounces, and comes to rest. Question: What is the probability the needle will come to rest on a line?
The picture below illustrates the problem. The distance between the lines is marked d, and the length of the needle is marked k. Let’s assume k is less than or equal to d. The illustration shows two possible resting points for the needle.
Looking at the picture, it’s easy to see how to approach the problem. All we care about is the horizontal “width” of the needle when it comes to rest, relative to the total distance between the lines d. The ratio of the former to the latter will be the probability of landing on a line.
In the picture, the horizontal width of the needle is given by
We use the absolute value since physical length is always positive. This is marked in the picture.
Here’s how we reason this out. First, the probability that the needle will land at any particular angle is just
And given the angle it happens to land at, the probability it will cross a line is
which is just the horizontal width of the needle divided by the distance between lines. (Note this only works for k <= d.)
Putting these two probabilities together — since both events must occur at the same time — we get the probability that a particular needle at angle theta will cross a line as
But this is only for one theta. What about the others? To find the probability that a dropped needle will hit a line for every possible theta, we have the following integral
Pulling out the constants, we can re-write this as
The key to simplifying this is to note the following relationship between ordinary cosine and the absolute value of cosine. For ordinary cosine, the integral between 0 and 2pi is just zero — half the time it’s positive over that range, and half the time it’s negative. But we want the absolute value of cosine, which is always positive.
The picture below illustrates how to translate between the two.
The picture shows regular cosine plotted between 0 and 2pi. In absolute value terms, the areas under the curve marked 1, 2, 3, and 4 are all equal. The two positive areas exactly equal the two negative areas. That’s another way of saying that the integral of
from 0 to 2pi is equal to four times the integral of
from 0 to pi/2. That means we can re-write our integral as
So the probability that a needle will land on a line is just
as long as k is less than or equal to d.
Now imagine we’re clever and choose sewing needles exactly the length of the width of boards in our floor. In that case, k = d. Then the probability it will hit a line becomes
Now we have an expression we can use to estimate pi. The process is simple.
Start tossing needles on the floor. Count how many land on the lines, as a percentage of total throws. That’s P(k,d). Then divide this number into 2. The result will be pretty close to pi. The more needles you throw, the better the estimate will get.
Believe it or not, there’s an enormous literature of mathematicians actually trying to estimate pi using some version of this method. It really works! And here is the internet rabbit hole you’re looking for, with everything you ever wanted to know about this so-called “Buffon’s Needle Problem.”