Search code examples
javatrigonometryradians

Java get cos or sin of angle


I have the folling:

double angle = 0.0;
double rad = Math.toRadians(angle);
double sinIs = Math.sin(rad);
double cosIs = Math.cos(rad);

I would expect the result to be:

rad=0.0
sinIs=0
cosIs=1

However the return Math.toRadians(0.0) will return

rad=2.356194490192345

Solution

  • Seems some issue at your end. I tested this code

    public static void main(String a1[]) 
        {
            double angle = 0.0;
            double rad = Math.toRadians(angle);
            double sinIs = Math.sin(rad);
            double cosIs = Math.cos(rad);
            System.out.print("sin-->"+sinIs+"\ncos-->"+cosIs);
        }
    

    Output

    sin-->0.0
    cos-->1.0