Tuesday, November 24, 2009

Further Geekery, "cos" I Can be Obssessive

In my last post, I alluded to the trigonometric functions related to a hexagon being something one could derive easily, but I didn't actually do it. I also alluded to being able to keep slicing up the triangles forever, but didn't say why.

I'm not going to prove the Pythagorean theorem here. If you don't remember it, here it is:


A2 + B2 = C2

So why did I choose a hexagon for my shape? There are a number of triangles with relationships that are relatively easy to describe mathematically. Two of them are the equilateral triangle and the right isosceles triangle.


The first triangle is a right isosceles triangle. By definition, the angle united the two equal sides is a right angle. If the length of the equal sides is 1, applying the Pythagorean theorem tells me that the length of the hypotenuse is √2. I considered using a square as my initial shape, but I suspected it would make it harder for me to cut up the angles later. I think it would actually be almost as easy, but it doesn't really matter.

The second triangle is an equilateral triangle. Equilateral triangles are cool because if I draw a line from the middle of one face to the opposite corner, I know that I've cut the opposite corner in half. I can then use the Pythagorean theorem to find the length of the new line. Now I know several important things about the triangle.

crdθ=1

sin(θ/2)=1/2

cos(θ/2)=(√3)/2

tan(θ/2)=1/(√3)=(√3)/3

These numbers are important because the angle θ/2, created by splitting an equilateral triangle, is the smallest one I know of that has trigonometric functions that can be worked out geometrically. After that, as far as I'm concerned, the trigonometric functions are buttons on my calculator. However, the calculator had to get its table somewhere, and creating such tables was the life's work of a few ancient mathematicians, to varying degrees of accuracy. They were able to do it because many of the formulas related to adding and subtracting and slicing up angles can be proven geometrically, and then applied to whatever number and measurement system seems like a good idea at the time. The formulas I'm interested in are the half-angle formulas.

sin2 x = (1 - cos 2x)/2

cos2 x = (1 + cos 2x)/2

What these formulas mean is that if I know the cosine of an angle, I can calculate the sine and cosine of half of that angle. If I can calculate the sine and cosine, I can also calculate the tangent. And I can do it again and again. That's important because the way my last post achieves higher degrees of accuracy in calculating pi is by inscribing polygons with higher and higher numbers of faces into the circle. The addition and subtraction formulas mean that it could be done with an arbitrary number of faces, but I think that the most reasonable choice is 6*2n with n being an integer. The half-angle formula has to be applied n times to give the correct cosine.

I hoped, when I figured that out, that there'd be some totally cool way to speed up the calculation. I don't think there is. If n=3, the polygon has 6*23=48 faces, the cosine of the angle at the apex of the 96 skinny right triangles is

cos(360°/96) = √(1+√(2 + √(2 + √(2 + √3)))/2)

Multiply that be twice the number of faces and you have your perimeter. For each iteration, the half-angle formula is applied again to that increasingly ugly number. No wonder Archimedes only went to 96 faces in his calculation. To get a little better than the level of accuracy of the 10,000-sided figure I suggest at the end of my post, it would take n=11, which is a lot of finding roots for anyone but a computer. To make it additionally difficult, the roots aren't rational numbers, so the computer would have to decide just how accurate an approximation he really needed; 11 approximations later, the number will have drifted pretty far from being exact.

To return to the point of my last post, if this were being applied to calculating pi, a person could get a little more accuracy each time he sliced the angle in half, approximated the trigonometric functions for the new angle, and re-calculated. The formula could even be restated like this:

6*2nsin(30/2n) < π < 6*2ntan(30/2n)

No comments: