Introduction: Liu Hui Estimation Method for Pi Using Codeblocks.

About: I am a STEM teacher, passionate about knowledge, with a petroleum engineering degree. Weird, huh?. With my teaching experience in subject like: Environmental systems and societies, Theory of knowledge, English…

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 Liu Hui´s method 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.

Liu 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. ------> 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.

And last, since we are going to rotate it using the center of the workplane as pivot we have to displace it half of the height in the Y axis. (Image 4).

With the triangle done, is a matter creating a new object called " polygon" of adding copies and rotating them using a loop and the "sides" variable. (Image 5).

Step 4: Create Any Polygon.

Now you just have to run the algorithm and change the number of sides and as you increase this number you will get a better approximation of a circle. For a better view you can use the group block to see how a circle emerges in front of your eyes.

Step 5: Final Thoughts

Liu Hui ´s intentions was to use a simple equation (area of a polygon with n numbers of sides) to compute a good approximation to the irrational number Pi in an era of simple calculations.

Since the area of the circle is Pi times the square of the radius. If you use a circle with the radius of 1, the value of the area is precisely Pi.

As teacher I believe this is a great example an opportunity for a STEM class, usign 3D design, math, geometry, coding, and even 3D printing to encourage kids to love math.

I leave here the link to the Codeblock: https://www.tinkercad.com/codeblocks/71hxQlLCBug

Pi Day Speed Challenge

Participated in the
Pi Day Speed Challenge