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.
Answer from azp74 on Stack Overflowuse 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.
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.
Videos
First of all, you should read the javadoc. sin(double) takes a double in parameter which is the angle in radians like said in the documentation. You'll also find on the linked page that sqrt takes a double as well.
Then, you should know that java can perform non-destructive conversion automatically. So if a method takes a double and you have a long, it will be no problem, since there's no loss in the conversion long -> double. The reverse is false, so Java refuse ton compile.
For the radians conversion, you'll find a toRadians method in the Math class.
- If you have value in degrees, just do
degrees * Math.PI / 180. Or better use function suggested by coobird in the comment (didn't know of it). - Yes, you can pass any double value in it. (Any number, for that matter.)
- No, both functions take
doubleparameter. Check the docs.
Are you trying to use degrees? Keep in mind that sin and cos are expecting radians.
Math.cos(Math.toRadians(354))
Math.cos and Math.sin take angles in radians, not degrees. So you can use:
double angleInDegree = 354;
double angleInRadian = Math.toRadians(angleInDegree);
double cos = Math.cos(angleInRadian); // cos = 0.9945218953682733