<PERSON> Estimation Method for Pi Using Codeblocks.
Introduction: <PERSON> Estimation Method for Pi Using Codeblocks.
Math is really fun if you come to understand its importance in describing our world. And one of those things that is almost everywhere is Pi, specially when it has to do with curves.
When I saw this challenge I had to participate and, as a teacher and Codeblocks fan, I knew I could mix these two in one instructable.
So I started my investigation, and found that Pi in ancient! And in ancient times there were no computers or powerful calculators, so they had to be really creative when estimating the value of this irrational number with infinite decimals.
I came across <PERSON> to estimate Pi. This Chinese mathematician used inscribed polygons (with a number of sides that are multiples of 6, ie: hexagon, dodecagon, and so on).
It is a beautiful example of creativity and use of geometry for calculation purposes. So let´s start.
Step 1: Understanding the Algorithm
As I said before, it is really cool to imagine people with little resources finding a way to do something complex for their time.
<PERSON> saw that the bigger the number of sides of a polygon, the more it resembles a circle. As you can see in the image a hexagon (green) is not a good approximation for a circle. But once you use a dodecagon (blue) you see that the sides resembles the circle better, and if you continue yo will get to the point where you wont be able to see a polygon, but a circle.
Another way to see this is: "A circle is a polygon with an infinite number of sides".
He stated that he could find a really good estimation of Pi by calculating the area of a polygon, because the second one was fairly doable at that time.
Using this scope, as a teacher you could:
- Teach or practice the concept of a limit.
- Teach or practice area calculations for polygons.
- Teach or practice angles and trigonometry calculations.
If you want to know a little bit more, please check the following page I used for reference:
https://luckytoilet.wordpress.com/2010/03/14/liu-h...
Step 2: A Regular Polygon As a Sum of Triangles
A regular polygon with x number of sides can be geometrically divided into an x number of isosceles triangles. Ie: In the first image you can see that a pentagon can be divided into 5 triangles, an hexagon into 6 and so on and so on. So when we can create a polygon using isosceles triangles.
That is what we are going to use in Codeblocks, by scaling roofs into specific isosceles triangles, we can create a regular polygon.
In image #2, we can see that:
1) The angle beta at the top of the triangle can be calculated by dividing 360 degrees by the number of sides of the polygon. ------> Beta = 360 / (number of sides)
2) The alpha angles are equal and can be calculated by subtracting beta to 180 and dividing by two, since all of the angles inside a triangle add to 180. -------> Alpha = ( 180 - Beta ) / 2
3) The side a is always equal to the radius of the circumference. -------> a = radius.
4) The height of the triangle h can be found using trigonometry with the sine of Alpha. 974
------> h = a * sin ( Alpha ).
5) The side b can be calculated using trigonometry with the cosine of Alpha. --------> b = 2 * a * cos ( Alpha ).
Step 3: Working With Codeblocks
The closest figure to a triangle in Codeblocks is a roof (Image 1). This roof has the following default dimensions: 20 mm lenght, 20 mm width and 10 mm the height. We have to take these proportions into account to accurately modify our roof. So this algorithm will be about modifying that roof.
First, we have to create a variable and that is the number of sides of the desired polygon. (Image 2).
Next we have insert a roof and modify it to be the isosceles triangle that we need. So we use the create object block and name it "triangle". after that we have to add a roof with a length of 2. (image 3).
Now we have to scale it. to the desired height and width. So we need the correct proportions. For the height we use the sine of Alpha (Z axis) and for the width we use the cosine of Alpha (X axis).
Next we rotate it 90 degrees to make it flat with the XY plane. 110