
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
18
|
Chapter 1: Numbers and Enumerations
In addition to these three static methods, the length of the hypotenuse of a right tri-
angle can be calculated using the Pythagorean theorem. This theorem states that the
hypotenuse of a right triangle is equal to the square root of the sum of the squares of
the other two sides. This equation can be realized using the
Math.Sqrt static method,
as follows:
double hypotenuse = Math.Sqrt((xSide * xSide) + (ySide * ySide));
where xSide and ySide are the lengths of the two sides that are not the hypotenuse of
the triangle.
Discussion
Finding the length of a side of a right triangle is easy when an angle and the length of
one of the sides are known. Using the trigonometric functions sine, cosine, and tan-
gent, you can derive the lengths of either of the two unknown sides. The equations
for sine, cosine, and tangent are defined here:
sin(Theta) = oppositeSide / hypotenuseSide
cos(Theta) = adjacentSide / hypotenuseSide
tan(Theta) = oppositeSide / adjacentSide
where theta is the value of the known angle. Rearranging these equations allows you
to derive the following equations:
oppositeSide = sin(theta) * hypotenuse;
oppositeSide = tan(theta) * adjacentSide;
adjacentSide = cos(theta) * hypotenuse;
adjacentSide = oppositeSide / tan(theta);
hypotenuse = oppositeSide ...