gpt4 book ai didi

java - 数学 arctan 不适用于 Android 项目

转载 作者:行者123 更新时间:2023-12-01 06:40:45 26 4
gpt4 key购买 nike

在下面的代码中,

float i = Float.parseFloat(a);
float j = Float.parseFloat(b);
double div = (double)j/i;
float theta = (float) Math.atan(Math.toRadians(div));

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

最佳答案

看起来您的转换到处都很奇怪。这就是我认为您想要的:

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
}
}

假设您想要 4/3 作为渐变,那根本就不是角度 - 因此在其上调用 Math.toRadians 是不合适的。您想要对渐变调用 Math.atan 来获取以弧度为单位的值,然后对弧度值调用 Math.toDegrees 来获取度数。

关于java - 数学 arctan 不适用于 Android 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11216729/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com