-2

次の計算を使用して測定値を計算しましたが、問題は計算を度数ではなくラジアンで出力することです.私の質問は、計算を出力度数に変換する方法です.Math.toDegressメソッドは知っていますが、 「この状況でそれを実装するのに問題があります。これは計算が行われる私の onCreate です:

public void onClick(View v) {
        // TODO Auto-generated method stub

        try {

            String getoffsetlength = data.offsetLength.getText().toString(); 
            String getoffsetdepth = data.offsetDepth.getText().toString(); 
            String getductdepth = data.ductDepth.getText().toString(); 

            double tri1,tri2;
            double marking1,marking2;


            double off1 = Double.parseDouble(getoffsetlength);//length
            double off2 = Double.parseDouble(getoffsetdepth);//depth
            double off3 = Double.parseDouble(getductdepth);//duct depth


            marking1 = Math.sqrt(Math.pow(off1,2) + Math.pow(off2,2));
            tri1 = Math.atan(off2 / off1);

            tri2 = (180 - tri1) / 2;
            marking2 = off3 / Math.tan(tri2);



            Intent myIntent = new Intent(MainActivity.this, CalcResult.class);
            myIntent.putExtra("number1", marking1);
            myIntent.putExtra("number2", marking2);
            startActivity(myIntent);
            //make a toast 
            Toast.makeText(getBaseContext(), "Calculating!", Toast.LENGTH_SHORT).show(); 



        } catch (NumberFormatException e) {
            // TODO: handle exception
            System.out.println("Must enter a numeric value!");


        }

    }


}
4

2 に答える 2

0

ラジアンから度への変換は、定数係数を使用した単純な乗算Math.toDegrees()です。理由がある場合は、自分で使用または定義してください。

public static final double TO_DEGREES = 180.0 / Math.PI;
public static final double TO_RADIANS = Math.PI / 180.0;

しかし、あなたのコードは間違っているように見えます:

Math.toDegrees(Math.sqrt(Math.pow(off1,2) + Math.pow(off2,2)));

これは次のように単純化できます。

Math.toDegrees(Math.sqrt(off1 * off1 + off2 * off2));

Math.sqrt(off1 * off1 + off2 * off2) で距離を計算しますが、この値を toDegrees に渡す角度として使用します。

それが正しいとは思えません。

あなたのコメントに答えるには:値「angleRadians」を度に変換します

Double angleDegrees = Math.toRadians(angleRadians);
于 2013-10-08T21:06:13.620 に答える