在 java 中,我试图用 cos 和 sin 对数字进行运算,但我总是得到负变量,谁能解释为什么?
这是我的代码:
double velocity_x=22*Math.sin(10);
double velocity_y=22*Math.cos(10);
他们都分别返回velocity_x=-11.968464439566135
和 velocity_y=-18.459573639681953
我做错了什么?
最佳答案
sin()
和 cos()
的参数是弧度,而不是度数。要转换,请乘以 π/180:
double velocity_x = 22 * Math.sin(10 * Math.PI / 180);
关于java - 无缘无故的负整数,cos,sin。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12738528/