如何使用Math.cos()和Math.sin()?
我正在使用Math.cos
和Math.sin
但它会返回我意想不到的结果:
Angle Sin Cos 354 0.8414 -0.5403 352 0.1411 0.98998 350 -0.958 -0.2836
为什么我得到这些结果?
你想尝试学位吗? 请记住, sin
和cos
都期待弧度。
Math.cos(Math.toRadians(354))
Math.cos
和Math.sin
以弧度而不是度数取角度 。 所以你可以使用:
double angleInDegree = 354; double angleInRadian = Math.toRadians(angleInDegree); double cos = Math.cos(angleInRadian); // cos = 0.9945218953682733
public static double sin(double a) Parameters: a - an angle, in radians. Returns: the sine of the argument.
您也可以使用它:
degrees *= Math.PI / 180; Math.cos(degrees)
没有一个答案符合我的需要。 这就是我的所作所为:
度数的窦(不是辐射)。 这就是你把它转回角度的方法:
double angle = Math.toDegree(Math.asin(sinusInDegree));
说明:如果你有一个三角形的两边,这是唯一对我有用的解决方案。 您可以使用正态度量度量来计算所有内容,但您必须将Math.asin()
转换回度以获得正确的度数。 🙂