Pythagoras

From GPWiki

Files:GUITutorial_warn.gif The Game Programming Wiki has moved! Files:GUITutorial_warn.gif

The wiki is now hosted by GameDev.NET at wiki.gamedev.net. All gpwiki.org content has been moved to the new server.

However, the GPWiki forums are still active! Come say hello.

A triangle has sides A, B and C. The angle between A and B is 90° or π/2 radians. For the length of the sides the following goes:

 |\
 | \
 |  \C
A|   \
 |____\
   B

Pythagoras' Theorem states:

A^2 + B^2 = C^2\,

or

C = \sqrt{A^2 + B^2}

This allows us to calculate the length of a line in 2 dimensional space if we know the x and y coordinates of the endpoints. If the two points P and Q are given by: P = (x_1, y_1)\, and Q = (x_2, y_2)\,

Then the length, L, of the line between two points P and Q is given by:

L = \sqrt{(x_1 - x_2)^2 + (y_1 - y_2)^2}

In 3D space, the z coordinates are included in a similar manner:

L = \sqrt{(x_1 - x_2)^2 + (y_1 - y_2)^2 + (z_1 - z_2)^2}

You can't do without Pythagoras, man.

For more info see: Pythagorean Theorem on Wikipedia