[英]math arctan does not work in android project
In the following code, 在以下代码中,
float i = Float.parseFloat(a);
float j = Float.parseFloat(b);
double div = (double)j/i;
float theta = (float) Math.atan(Math.toRadians(div));
theta
gets the wrong value. theta
得到了错误的值。 As far I can see, it always computes Math.tan
(I tried this also and it gives me the same results). 据我
Math.tan
,它总是计算Math.tan
(我也尝试过这样做,并且得到的结果相同)。 So even if I write Math.tan
or Math.atan
, I get the same results. 因此,即使我编写
Math.tan
或Math.atan
,我Math.tan
得到相同的结果。
Can anyone help me? 谁能帮我?
Specific examples: 具体示例:
i,j----> theta I get:
3,4-----> 0.023 while the correct one is arctan(4/3)=53.13 not tan(4/3)=0.023
3,6-----> 0.052 while the correct one is arctan(9/3)=71.56 not tan(9/3)=0.052
Looks like you're converting oddly all over the place. 看起来您到处都是奇怪的转换。 Here's what I think you want:
这是我想您要的:
public class Test {
public static void main(String[] args) throws Exception {
double div = (double)4/3;
float theta = (float) Math.toDegrees(Math.atan(div));
System.out.println(theta); // 53.130104
}
}
Assuming you want 4/3 as the gradient, that isn't an angle at all - so calling Math.toRadians
on it is inappropriate. 假设您要使用4/3作为渐变,那根本不是一个角度 -因此在其上调用
Math.toRadians
是不合适的。 You want to call Math.atan
on the gradient to get the value in radians, and then Math.toDegrees
on the radians value to get degrees. 您要在渐变上调用
Math.atan
以获取弧度值,然后在弧度值上Math.toDegrees
以获取度数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.