java 使用 Math.cos() 以度数计算角度的余弦

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17781313/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-01 14:58:17  来源:igfitidea点击:

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

javamath

提问by Omiye Jay Jay

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.

我想以度数给出 java 中的 Math.cos() 方法的结果。我尝试过从弧度转换为度数的方法。但是我发现我传递给 Math.cos() 方法的任何数字都被视为弧度,无论我是否转换。请我让它给我度数的结果。谢谢。

采纳答案by NPE

I discovered that any number I pass into the Math.cos()method is being treated as radians, irrespective of whether I convert.

我发现我传递给该Math.cos()方法的任何数字都被视为弧度,无论我是否进行转换。

The discovery is quite correct, and is precisely why you convert. Once you've done the conversion, you pass the resultant angle (which is in radians) to Math.cos(), and everyone is happy.

这个发现是非常正确的,这正是你皈依的原因。完成转换后,将生成的角度(以弧度为单位)传递给Math.cos(),每个人都很高兴。

回答by azp74

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

例如,使用 Math.toRadians 将度数转换为弧度以传递给 Math.cos

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

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

我想这就是你要问的。这里有很多类似的问题。

回答by Maroun

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

您可以使用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:

请注意,public static double cos(double a)期望以弧度为单位的参数:

a - an angle, in radians.

a - 一个角度,以弧度为单位。