math arctan在android项目中不起作用

gho*_*der 0 java math

在以下代码中,

float i = Float.parseFloat(a);
float j = Float.parseFloat(b);
double div = (double)j/i;  
float theta = (float) Math.atan(Math.toRadians(div));
Run Code Online (Sandbox Code Playgroud)

theta获得错误的价值.到目前为止,我可以看到,它总是计算Math.tan(我也尝试了这个,它给了我相同的结果).所以,即使我写Math.tanMath.atan,我得到相同的结果.

谁能帮我?

具体例子:

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
Run Code Online (Sandbox Code Playgroud)

Jon*_*eet 11

看起来你在整个地方奇怪地转换.这是我认为你想要的:

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
    }
}
Run Code Online (Sandbox Code Playgroud)

假设你想要4/3作为渐变,那根本不是一个角度 - 所以调用Math.toRadians它是不合适的.你想调用Math.atan渐变来获得Math.toDegrees弧度值,然后调用弧度值来获得度数.