如何使用Math.cos()和Math.sin()?

joa*_*pez 13 java math

我正在使用Math.cos,Math.sin但它会给我带来意想不到的结果:

 Angle   Sin      Cos
 354     0.8414  -0.5403
 352     0.1411   0.98998
 350    -0.958   -0.2836
Run Code Online (Sandbox Code Playgroud)

为什么我得到这些结果?

Pub*_*bby 60

你想尝试学位吗?请记住,sincos期待弧度.

Math.cos(Math.toRadians(354))
Run Code Online (Sandbox Code Playgroud)


ass*_*ias 17

Math.cosMath.sin弧度角度,而不是度.所以你可以使用:

double angleInDegree = 354;
double angleInRadian = Math.toRadians(angleInDegree);
double cos = Math.cos(angleInRadian); // cos = 0.9945218953682733
Run Code Online (Sandbox Code Playgroud)


Nik*_*sov 5

public static double sin(double a)

Parameters:
a - an angle, in radians.
Returns:
the sine of the argument.
Run Code Online (Sandbox Code Playgroud)