0

I am trying to calculate the sides of a right triangle given an angle theta and the hypotenuse. I specify that the hypotenuse should be equal to five. Then I calculate the sides using cos and sin, as per standard trig. What I find after the side lengths are calculated is that the hypotenuse is actually 5.000000000002 long, or something as ever so slightly off from exactly 5. For the purposes of the code I am writing, I would prefer that if I can't get a perfect hypotenuse length of 5, I would rather the program return side lengths that corresponded with a hypotenuse length of 4.99999999999, or however close to 5 as possible on the lesser side. All of my numbers are doubles. Any idea if this can be done?

I am writing in Java.

Dylan Russell
  • 936
  • 1
  • 10
  • 29

0 Answers0