If you think about it, pi is really weird. This irrational number shows up in the craziest places. If you swing a mass back and forth on a string, there's a pi in there. It pops up in the Heisenberg uncertainty principle, Einstein's general relativity, and the interaction between two electric charges.
Of course, most people associate pi with circles. That's understandable, since the most basic definition of pi is the ratio of the circumference to the diameter of a circle:
Now for the important part. Today, as you may know, is Pi Day. Why today? Because it’s March 14—yes, 3/14—and 3.14 is the value of pi to two decimals. Of course, the actual number continues to an infinite number of decimal places: 3.14159265359 … and so on, forever. That’s why it’s called irrational.
I should add that the US is pretty much the only place that uses the middle-endian date format of month/day/year. If you go with the little-endian format of day/month/year, then today is 14/3—which is obviously not pi. (In that case I suggest July 22, since the fraction 7/22 is a fairly decent approximation for pi.)
Anyway, my traditional way of celebrating Pi Day is to find a new way each year of calculating a numerical value for pi. It's just what I do. I've been at this for quite some time now, so here are some of my favorites:
- Finding pi using random numbers (and Python)
- Determining the value of pi using a mass oscillating on a spring
- Actually measuring the circumference and diameter of real circles
I have even more Pi Day posts here. But now let's try this a new way. Let’s see how close we can get to pi by drawing a circle.
Here's how this will work. You draw a circle. From that circle, you can determine both the circumference and the radius. Then the value of pi would be the circumference divided by twice the radius. Simple, right?
Oh, but what if your circle isn't perfect? I mean, who draws perfect circles anyway? Let's imagine that this un-perfect circle is actually a bunch of discrete points connected by line segments. If you zoomed in on a part of it, it might look like this:
Now I can find the distance between each successive point using the following formula:
For the total circumference, I can just add up all these distances. That should work just fine. But what about the radius? Let’s assume there is a known center of the imperfect circle. In that case, I can calculate the radius as the average distance from the center to all the points making up the circle.
So I wrote this Python script to do the math. Try it out below! Draw the best circle you can by dragging the yellow ball around the central white ball. After you make it all the way around, the program calculates the circumference and radius of your circle—and from that, the value of pi. You can see the code by clicking the pencil icon. To run it again, click the Play button.
I'll be honest—this could be better. Things always get a little wonky when you add mouse interactions to VPython (at least they do for me), so this presented a unique set of problems. But I like to keep things as simple as possible.
Now for the Pi Day Challenge. (Yes, I'm making my own challenge.) Can you draw a circle for a calculated pi value that is close to 3.14159265359? How many decimal places can you nail? Can you get a better value than your friends? Let's see!