On this page, you can approximate the value of pi using regular polygons. Adjust the polygon's number of sides with the slider, or enter a number into the text box.
The mathematical constant pi is defined to be the ratio of a circle's circumference to its diameter. For example, the unit circle (a circle with radius 1) has a circumference of 2π and a radius of 2.
We can approximate the circumference of a circle by drawing a polygon inside the circle, then measure the perimeter of the polygon. Using this approximation, we can calculate an estimate for pi by dividing with twice the radius of the circle.
Suppose you are stranded on a desert island and you need to finish your trigonometry homework. The last question on your homework assignment is: Convert 21.742 degrees to radians. But a cocunut fell on your head, and you forgot every single digit of pi!!! All you have is a straightedge, a blank notebook, and a pencil. How can you finish your homework in time for class tomorrow???
You think quicky, and remember that pi is the ratio of a circle's diameter to it's circumference, and draw a circle with a radius of 1 inch. Inside the circle, you draw a regular 100,000 sided polygon so that the circle passes through every vertex of the polygon. Then you measure one of the sides of the polygon and multiply that by 100,000 to compute the perimeter of the polygon. Now you have a pretty good estimate of the circumference of the circle (6.283185363507899 inches, to be exact). You divide by two and get 3.141592681753949, a pretty decent estimate for pi.
With your estimate for pi, you can now convert the degree value to radians, using the formula: 180 / π = 21.742 / r. You do a little bit of algebra and do the calculation in your head: r = 3.141592681753949 × 21.742 / 180 = 0.37946948937. Congrats! You finished your homework and you still have plenty of time to build a signal fire to alert the search party!
This isn't a good way to estimate pi. In fact, for this webpage, I used JavaScript's built in pi constant to compute the polygon side lengths! I created this page to make a fun visualization with an educational spin.
You may notice that accuracy actually goes down if you increase the vertex count high enough. In theory this pi estimation should converge at π if we made the vertex count arbitrarily large. However, floating point numbers are not precise enough for this type of calculation. Small inaccuracies in floating point numbers can result in larger problems. For example, if you use a polygon with 596313653 sides, the error will be 29%, giving us a less accurate estimation than a triangle!
To calculate the polygon side length, I used the Law of Cosines.
To visualize, draw lines from the center of the circle to each vertex.
This splits the polygon into triangles. From here, we can calculate
1 nth of the n-gon's perimeter by using the Law of
cosines. Since units don't matter here, assume the radius of the circle
is 1 unit. This simplifies our caluclation to
l^2 = 2 - 2 cos(2π / n).
Multiply l by n to get the perimeter of the n-gon,
which is an estimate for the circumference of the unit circle, which is
2π. Divide the perimeter by 2 for the final estimate for pi.
The perimeter calculation involves dividing by n. If n
is large enough, the result of this calcluation can be truncated to 0.
For example, if we use a 596313653-gon, we will have to do the
computation: Math.cos((2 * Math.PI) / 596313653) = 0.9999999999999999
.
But if we try with a polygon with just one more side, we get the
following: Math.cos((2 * Math.PI) / 596313654) = 1
.
This completely
messes up our calculation of the polygon's perimeter, we end up with
P = n × sqrt(2 - 2) = 0, giving us the wildly inaccurate estimate
of π = 0.
For more info, see: floating point standard and JavaScript numbers.
I had a lot of fun making this mini-site, and I hope you enjoyed visiting! Keep an eye out for more fun next year! All the calculations are done in JavaScript, and I made the circle diagram with JavaScript's canvas API.