Reputation: 1
I tried using both but its giving me wrong answers, according to my calculator the answer should be:
arctan(0.35) = 19.29
What I used:
Math.atan(Math.toRadians(angle)) and Math.atan();
Upvotes: 0
Views: 408
Reputation: 10051
The methdo Math.atan()
returns a result in radians:
Returns the arc tangent of a value; the returned angle is in the range -pi/2 through pi/2. Special cases:
If the argument is NaN, then the result is NaN. If the argument is zero, then the result is a zero with the same sign as the argument. The computed result must be within 1 ulp of the exact result. Results must be semi-monotonic.
To obtain the value in degrees just perform a transformation:
@Test
public void arctan() {
double result = Math.atan(0.35);
assertThat(result*180/Math.PI).isBetween(19.29, 19.2901);
}
Upvotes: 0
Reputation: 38424
Your result is in degrees, not radians.
Math.toDegrees(Math.atan(0.35))
returns
19.290046219188735
which is your "expected" value. Make sure your inputs and outputs are in the correct unit!
Upvotes: 7