Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cos() - need cosin to return in degrees not radians 1

Status
Not open for further replies.

axtec

Programmer
Dec 12, 2001
21
0
0
US
I need to find the cosin of an angle, but the result is returned in radians. The problem I am trying to solve is this: Y = cos(angle) * 12. It should be really simple, but when the result of cos(angle) is in radians, the answer is not correct. If I convert the result of cos(angle) to degrees, it is incorrect as well. Using a calculator,
cos(45) * 12 is 8.48. In java, cos(45) * 12 is 6.30. Thanks.
 
It is inconceivable that if you convert the result in radians to degrees that the result doesn't agree with the calculation done explicitly in degrees. I can only suspect that you are overlooking some detail of the calculation.

It turns out that you are confused about the parameter that Math.cos() takes. The argument is the angle "in radians" not in degrees. Try this

double angle = 45 * Math.PI / 180; // Convert degrees to radians
double result = Math.cos(angle) * 12; // result is 8.48

Regards,

Charles
 
Yep, that's it. I forgot to 'Math.toRadians(angle)' first. I knew it had to be something like that. Thanks for your help. Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top