Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Math.cos() to find cosine of angle in degrees [duplicate]

Tags:

java

math

I want to give the result the Math.cos() method in java in degrees.I have tried methods like converting from radians to degrees. But I discovered that any number I pass into the Math.cos() method is being treated as radians,irrespective of whether I convert.Please I can I make it give me the result in degrees.Thanks.

like image 616
Omiye Jay Jay Avatar asked Dec 03 '22 22:12

Omiye Jay Jay


2 Answers

use Math.toRadians to convert your degrees to radians to pass to Math.cos for example

double blah = Math.cos(Math.toRadians(50));

I think that is what you are asking. There are quite a lot of similar questions here.

like image 144
azp74 Avatar answered Jan 18 '23 07:01

azp74


You can use Math.toDegrees()/Math.toRadians()

Converts an angle measured in radians to an approximately equivalent angle measured in degrees/radians.

Note that public static double cos(double a) expect the parameter in radians:

a - an angle, in radians.

like image 28
Maroun Avatar answered Jan 18 '23 09:01

Maroun