![]() A simple one is to randomly throw darts at a dart board that looks like this: There are a couple different ways of estimating $\pi$. All you have is the p5.js web editor! What to do!? (FYI: Try not to think about giving up and just enjoying the island.) We can see how the actual value of Math.PI fits within the range Archimedes calculated.You are trapped on a deserted island by a psychopath who is keeping you there until you can determine the digits of $\pi$ out to many decimal places. ![]() When we bring up our Console, we would see something like the following: 3.140845070422535: lower bound! To follow along, create a new HTML file, add the above contents into it, and open this file in the browser. If we turned all of this into JavaScript (with the supporting HTML), what we would see would be something that looks as follows: Ĭonsole.log(Math.PI ": value for Math.PI!") What Archimedes concluded is that the value for pi would fall between 223/71 on the lower end and 22/7 on the upper end. Eventually, a whopping 96 sides later, Archimedes came up with the following range for the value of pi: The inner polygon’s perimeter would be the lower bound of a circle’s circumference:Īs Archimedes added more sides to the polygons, he was able to more accurately wrap the circle and found that the approximation for pi became more accurate as well. The outside polygon’s perimeter would be the upper bound of a circle’s circumference. So what Archimedes did was take a circle and wrap it with polygons on the inside and the outside. While measuring the circumference of a circle accurately was tricky, measuring the perimeter of shape with straight lines that we could easily measure like a polygon was not very tricky: The earliest approaches for calculating pi were of the geometric kind by Archimedes. Now, if you are down for learning how to calculate pi using some common techniques spanning all the way from 2000 years ago to more modern times, read on! Polygon Approximation - 250 BC If this is what you were looking for, the rest of the content here is around how we can generate this value ourselves. This will give you a version accurate enough to use for most calculations. This is going to be a fun activity that ties together some of the more basic JavaScript concepts around functions, looping, console logging, and mathematical operators.īefore I go too far here, if you are here to just get a value of pi that you can use in your JavaScript apps, you have ready access to that by using the Math.PI constant: console.log(Math.PI) // 3.141592653589793 What we are going to do in this article is look at a few popular approaches for calculating pi and reimplement them ourselves in JavaScript. Notice that each major increase in the precision of pi was marked by some major technical advancement such as better ways to take measurements, new mathematical techniques, or the invention of the computer. This is highlighted by the following visual from Google: The value for pi got more precise as time went on and people developed better techniques for calculating its true value. This constant value became cemented as the greek letter, π or commonly referred to as pi in English: This value never changed no matter the size of the circle. With these two important details chalked out, what people found is that the ratio between the circumference and the diameter turned out to be a constant value. If we had to visualize those two things, it would look a little something like the following: The diameter, which is the distance across the center of the circle.The circumference, which is the distance around the circle.Originally, they way we calculated PI was by taking a circle and measuring two things: How did we arrive at this value for pi? The answer to this is rooted in thousands of years of history where, for a really REALLY long time, we have been trying to figure out what the value of pi is via a bunch of clever and cutting-edge techniques. Today, we know that the value of pi is around 3.14.
0 Comments
Leave a Reply. |