I'm using Math.cos and Math.sin but it returns me unexpected results like these:
Angle Sin Cos
354 0.8414 -0.5403
352 0.1411 0.98998
350 -0.958 -0.2836
Why I get these results?
I'm using Math.cos and Math.sin but it returns me unexpected results like these:
Angle Sin Cos
354 0.8414 -0.5403
352 0.1411 0.98998
350 -0.958 -0.2836
Why I get these results?
Are you trying to use degrees? Keep in mind that sin and cos are expecting radians.
Math.cos(Math.toRadians(354))
Math.cos and Math.sin take angles in radians, not degrees. So you can use:
double angleInDegree = 354;
double angleInRadian = Math.toRadians(angleInDegree);
double cos = Math.cos(angleInRadian); // cos = 0.9945218953682733
public static double sin(double a)
Parameters:
a - an angle, in radians.
Returns:
the sine of the argument.
You can use this also:
degrees *= Math.PI / 180;
Math.cos(degrees)
None of the answers fitted my needs. Here's what I had:
A sinus in degree (not radiant). This is how you turn it back into a degree angle:
double angle = Math.toDegree(Math.asin(sinusInDegree));
Explanation: If you have 2 sides of a triangle, it's the only solution that worked for me. You can calcluate everything using the normal degree metric, but you have to convert the Math.asin() back to degree for the right result. :)