2014-01-26 121 views
1

一個簡單的問題。我似乎無法找到將餘弦轉換爲輻射度或度數的函數。 在下面的代碼將餘弦/正弦轉換爲Java中的程度

public class angle{ 

    public static void main (String[] args){ 
     int a = 30; 
     int b = 40; 
     int y = 88; 
     double c = Math.sqrt((a*a) + (b*b) - (2*a*b*Math.cos(Math.toRadians(y)))); 
     System.out.println("C = " + c); 
     double L = ((b*b) + (c*c) - (a*a))/(2*b*c); 
     System.out.println("Cos Alpha = " + L); 
     double B = ((a*a) + (c*c) - (b*b))/(2*a*c); 
     System.out.println("Cos Beta = " + B); 

    } 
} 

我有L和B餘弦,但我需要他們的程度的輻射。任何人有任何想法,我應該使用什麼功能? 在此先感謝。

+0

請檢查Math對象文檔中的方法。它有一些很好的命名方法。 –

+3

餘弦不是一個角度。如果你想要的角度是一個餘弦的那麼你使用arccos,然後推測Math.toDegrees ... –

回答

0

您可以使用Math.sin()& Math.cos()函數,其中參數以弧度給出。

1

Math類適合您的需求。例如,以下課程計算一個角度的餘弦。看看所有其他方法。

public class CosineTest{ 

     public static void main(String args[]){ 
     double degrees = 45.0; // put your value here 
     double radians = Math.toRadians(degrees); // look to the Math class..a lot of nice stuff here 

     System.out.format("The cosine of %.1f degrees is %.4f%n", 
          degrees, Math.cos(radians)); 

     } 
    }