0

次のコードでは、

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.tanなので、 orと書いてもMath.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
4

1 に答える 1

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

グラデーションとして 4/3 が必要だと仮定すると、それはまったく角度ではないため、それを呼び出すMath.toRadiansのは不適切です。Math.atanグラデーションを呼び出して値をラジアンで取得し、次にMath.toDegreesラジアン値を呼び出して度を取得します。

于 2012-06-26T22:30:23.590 に答える