2014-01-26 38 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)); 

     } 
    }