double theta = Math.Atan(OppositeSide / AdjacentSide); theta = Math.Acos(AdjacentSide / Hypotenuse); theta = Math.Asin(OppositeSide / Hypotenuse);
To get the angle in degrees, use the following code:
double theta = Math.Atan(oppositeSide / adjacentSide) * (180 / Math.PI); theta = Math.Acos(adjacentSide / hypotenuse) * (180 / Math.PI); theta = Math.Asin(oppositeSide / hypotenuse) * (180 / Math.PI);
theta is the known angle value, the
oppositeSide is equal to the length of the side
opposite to the angle, and
adjacentSide is equal to the length of the side
adjacent to the angle. The
hypotenuse is the
length of the hypotenuse of the triangle. See
Figure 1-1 in Recipe 1.14
for a graphical representation of these sides of a right triangle.
In some cases, we need to determine an angle of a right triangle when
only the lengths of two sides are known. The three trigonometric
arcsine, arccosine, and arctangent allow
us to find any angle of a right triangle, given this information. The
Math.Asin on the
Math class provide the functionality to implement
these trigonometric operations.
See Recipe 1.14; see the “Math Class” topic in the MSDN documentation.