Home > Enterprise >  Difficulty calculating Law of Sines in Java
Difficulty calculating Law of Sines in Java

Time:06-13

In this, I'm trying to follow law of sines in order to find angle A. The correct answer for this is 39.41 but for some reason, I'm not getting the correct inverse sine value. How can I fix this?

Visualization of the problem

import static java.lang.Math.*;
public class test
{
    public static void calculateAzimuth()
    {
        double a = 90;
        double A = 0;
        double c = 132.3459;
        double C = 111;
        
        //         a          C     c
        //sine^-1( 90* ( (sine111) /132.3459)) = A
        C = sin(toRadians(C));
        A = C/c; 
        A = (A*a);
        A = asin(A);
        System.out.println("Angle "   A);
    }
}

CodePudding user response:

You're not converting A to a value in degrees. It's still in radians.

CodePudding user response:

call toDegrees on your result

public static void main(String[] args) {
    double a = 90;
    double A = 0;
    double c = 132.3459;
    double C = 111;

    A = asin( sin(toRadians(C)) / c * a);
    System.out.println("Angle "   toDegrees(A));
}
  • Related