
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Finding the Length of Any Three Sides of a Right Triangle
|
17
• Casting from a float or double to a decimal results in the float or double being
rounded to 28 decimal places.
• Casting from a
double to a float results in the double being rounded to the near-
est
float value.
• Casting from a
decimal to a float or double results in the decimal being rounded
to the resulting type (
float or double).
• Casting from an
int, uint,orlong to a float could result in the loss of precision,
but never magnitude.
• Casting from a
long to a double could result in the loss of precision, but never
magnitude.
See Also
See the “Checked Keyword” and “Checked and Unchecked” topics in the MSDN
documentation.
1.14 Finding the Length of Any Three Sides
of a Right Triangle
Problem
You need to calculate the length of one side of a triangle when either the lengths of
two sides are known or one angle and the length of a side are known.
Solution
Use the Math.Sin, Math.Cos, and Math.Tan methods of the Math class to find the length
of one side. The equations for these methods are as follows:
double theta = 40;
double hypotenuse = 5;
double oppositeSide = 0;
double adjacentSide = 0;
oppositeSide = Math.Sin(theta) * hypotenuse;
oppositeSide = Math.Tan(theta) * adjacentSide;
adjacentSide = Math.Cos(theta) * hypotenuse;
adjacentSide = ...