0
votes

I'm trying to convert the sine of an angle from radians to degrees and I keep getting inaccurate numbers. My code looks like this:

public class PhysicsSolverAttempt2 {
    public static void main(String[] args) {
        double[] numbers = {60, 30, 0};
        double launchAngle = Double.parseDouble(numbers[0]);
        double iV = Double.parseDouble(numbers[1]);
        System.out.println(launchAngle);
        double iVV = iV * Math.toDegrees(Math.sin(launchAngle));
        System.out.println(Math.toDegrees(Math.sin(launchAngle)));
    }
}

When I use Math.sin(launchAngle), it gives me a perfect output in radians. However, when I convert the radians to degrees using the Math.toDegrees() function at the end, it gives me -17.464362139918286, though performing the same calculation with a calculator yields the number 0.86602540378. Am I using Math.toDegrees() incorrectly, or do I need to perform extra steps to get an accurate result?

3
What are you using to convert radians to degrees on your calculator?Jacob G.
Please clarify the question-- I don't know what you are trying to ask.Joshua Kingofasgard
"though performing the same calculation with a calculator" - What calculation?Jacob G.
Irrelevant but why did you use Double.parseDouble()? The numbers array is already a Double array. Your unnecessarily casting a Double to a Doubleakmin
You're looking for Math.sin(Math.toRadians(launchAngle)).Louis Wasserman

3 Answers

0
votes

Math.sin() accepts only radians as it's input. It appears your trying to find the sin of launchAngle, which is in degrees.

Math.toDegrees(Math.sin(Math.toRadians(launchAngle)));

0
votes

The sine function returns the y-coordinate of a point on the unit circle. For Math.sin, you input an angle in radians and it returns the corresponding y-coordinate. However, what you are doing here is using the result of Math.sin (a y-coordinate, not an angle) as the argument for Math.toDegrees, which is supposed to convert radians to degrees. I assume the intention was to find the sin of the launchAngle. If so, turn

Math.toDegrees(Math.sin(launchAngle))

into

Math.sin(Math.toRadians(launchAngle))
0
votes

It seems like the easiest way to find an accurate measurement is to simply multiply the initial degree measurement by Math.PI/180 and to use that number for calculations.

From there, Math.sin(launchAngle) will give clean, workable results.