java 方法的数学表达式?
Math expression to java method?
我有一个数学表达式,我需要将其表示为 Java 代码,最终结果以度为单位。我做错了什么,因为根据计算器,结果应该是 -4.812,但在编译代码时我得到的是 0.849。如果有任何帮助,我将不胜感激。
下面是我的一些代码片段:
public E6B()
{
d = 340;
w = 255;
va = 95;
vw = 8;
}
public double windCorAng()
{
double test1 = Math.toDegrees(Math.asin ( vw * Math.sin(w-d)/va));
return test1;
}
根据 Math.sin
's documentation, its argument should be given in radians, no degrees. You can use Math.toRandians
将这些度数转换为弧度:
double test1 = Math.toDegrees(Math.asin ( vw * Math.sin(Math.toRadians(w-d))/va));
// Here ------------------------------------------------^
您正确地注意到 asin
returns 是一个弧度角,因此您添加了 Math.toDegrees
。但是,sin
也接受以弧度为单位的角度!你现在传递的 (w - d
) 似乎是一个角度。您需要将其转换为弧度:
double test1 = Math.toDegrees(Math.asin ( vw * Math.sin(Math.toRadians(w-d))/va));
我有一个数学表达式,我需要将其表示为 Java 代码,最终结果以度为单位。我做错了什么,因为根据计算器,结果应该是 -4.812,但在编译代码时我得到的是 0.849。如果有任何帮助,我将不胜感激。
下面是我的一些代码片段:
public E6B()
{
d = 340;
w = 255;
va = 95;
vw = 8;
}
public double windCorAng()
{
double test1 = Math.toDegrees(Math.asin ( vw * Math.sin(w-d)/va));
return test1;
}
根据 Math.sin
's documentation, its argument should be given in radians, no degrees. You can use Math.toRandians
将这些度数转换为弧度:
double test1 = Math.toDegrees(Math.asin ( vw * Math.sin(Math.toRadians(w-d))/va));
// Here ------------------------------------------------^
您正确地注意到 asin
returns 是一个弧度角,因此您添加了 Math.toDegrees
。但是,sin
也接受以弧度为单位的角度!你现在传递的 (w - d
) 似乎是一个角度。您需要将其转换为弧度:
double test1 = Math.toDegrees(Math.asin ( vw * Math.sin(Math.toRadians(w-d))/va));