The Pythagorean theorem
The most widely used triangles are right-angled triangles. There are many interesting properties of right-angled triangles that can be used in games to make life easier. One of the famous properties is that the square of the hypotenuse of a right-angled triangle is equal to the sum of the squares of the other two sides.
Getting ready
The hypotenuse of a triangle is the longest side of a right-angled triangle, as shown in the following diagram:
If the hypotenuse is denoted as h, the Pythagorean theorem can be written as follows:
h2 = a2 +b2
If you take the square root of both the sides, you will get the following:
h = sqrt(a2+b2)
This means that if we know the length of any two sides of a right-angled triangle, we can easily find the length of the third side.
When working with the game's Artificial Intelligence (AI), we will be using the Pythagorean theorem frequently to calculate which agent is closer to the object. If side A is bigger than side B, then it will always be...