Tuesday, April 7, 2009

Generate Pythagoras Triangles

Triangles containing a right angle are called Pythagorean triangles. Their side lengths have a simple relationship. The sum of the squares of the shorter side lengths equals the square of the length of the longer side.

A simple example is a triangle with side lengths:

3, 4 and 5

since

32 + 42 = 9 + 16 = 25 = 52

Some other examples are:

5, 12, 13

(25 + 144 = 169)

6, 8, 10

(36 + 64 = 100)

7, 24, 25

(49 + 576 = 625)

20, 21, 29

(400 + 441 = 841)

You can find some of these yourself as they fall into patterns. For example:

3, 4, 5
5, 12, 13
7, 24, 25

The first numbers in each row are the odd numbers 3, 5, 7 ...

To find the second number add the first number to the first two numbers in the previous row. So for the row starting with 5, add this 5 to the 3 and 4 from the previous row: 5 + 3 + 4 = 12. To get the final number just add one to the second number: 12 + 1 = 13.

Let's work out the next row. The odd number after 7 is 9:

9

Add 9 to the first two numbers in the previous row to get the second number: 9 + 7 + 24 = 40

9, 40

And add one more to get the final number is 40 + 1 = 41

9, 40, 41

(92 + 402 = 81 + 1600 = 1681 = 412)

Another way to get the second and third numbers is to square the first number and halve the result. The second and third numbers are the whole numbers on either side. So for this last row: 92 = 81. Half of this is 40.5. So the second and third numbers are 40 and 41.

This method does not generate every possible Pythagorean Triangle. I'll leave that for another time.