This is an educational project that aims to show how pi works, and how that definition can be used to calculate it.
In this example a square is made. Then a circle with the radius of half the square's length is used, making it fit perfectly within the square. Now we create random coordinates within the square and use pythagoras to decide if the coordinate is within the circle (it's distance to the center would be less then the circle radius). If this is done let's say 10 times, and 8 points would be within the circle, that means that on average the ratio of [surface area circle : surface area square] is about [8:10].
If we understand that 4*r^2
is the surface area of the full square, and pi*r^2
is the surface area of the circle, we understand that pi is this ratio of circle:square times four. So by rougly calculating this ratio we can also calculate pi
In the example we don't use 10 but rather 500 or a thousand random points to calculate this ratio as closely as possible.