Results 1 to 15 of 15
Thread: Why doesn't Math.tan() work?
 08092011, 06:37 AM #1Member
 Join Date
 Jan 2010
 Posts
 43
 Rep Power
 0
 08092011, 06:39 AM #2
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,402
 Blog Entries
 7
 Rep Power
 25
The trig methods take radians, not degrees. See the Math class for methods that convert degrees to radians.
kind regards,
JosLast edited by JosAH; 08092011 at 06:43 AM. Reason: duplicate word ...
Build a wall around Donald Trump; I'll pay for it.
 08092011, 06:41 AM #3Member
 Join Date
 Jan 2010
 Posts
 43
 Rep Power
 0
Ah! I've been searching google for "java tan bug" this whole time. Thanks!
 08092011, 06:49 AM #4
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,402
 Blog Entries
 7
 Rep Power
 25
Build a wall around Donald Trump; I'll pay for it.
 08092011, 06:54 AM #5Member
 Join Date
 Jan 2010
 Posts
 43
 Rep Power
 0
Ok. Sorry to come back with another question but I'm pretty bad at math in general.
Java Code:angle = Math.atan(Math.toRadians(1)); System.out.println("angle: " + angle);
Prints angle: 0.017451520651465824
This works
Java Code:angle = Math.tan(Math.toRadians(45)); System.out.println("angle: " + angle);
 08092011, 06:58 AM #6
Read the API, don't guess around. In any case, why should the argument to atan(...) be in radians (or even degrees, for that matter)?
db
 08092011, 07:01 AM #7
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,402
 Blog Entries
 7
 Rep Power
 25
The tan( ... ) method takes a number in radians and returns a number without a dimension so the inverse of the method (atan) takes a number without a dimension and returns a number measured in radians; so make that snippet:
Java Code:angle = Math.toRadians(Math.atan(1));
kind regards,
JosBuild a wall around Donald Trump; I'll pay for it.
 08092011, 07:10 AM #8Member
 Join Date
 Jan 2010
 Posts
 43
 Rep Power
 0
Ok. Again thank you. This saved me from an hour of hair pulling.
Read the API, don't guess around.
public static double atan(double a)
Returns the arc tangent of an angle, in the range of pi/2 through pi/2. Special cases:
If the argument is NaN, then the result is NaN.
If the argument is positive zero, then the result is positive zero; if the argument is negative zero, then the result is negative zero.
A result must be within 1 ulp of the correctly rounded result. Results must be semimonotonic.
Parameters:
a  the double value whose arc tangent is to be returned.
Returns:
the arc tangent of the argument.
 08092011, 07:24 AM #9
 08092011, 08:11 AM #10Member
 Join Date
 Jan 2010
 Posts
 43
 Rep Power
 0
Certainly.
Java 2 Platform SE v1.3.1: Class Math
I think it may be an older API. I've been using the older api without issues thus far though.
 08092011, 08:20 AM #11
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,402
 Blog Entries
 7
 Rep Power
 25
Fun; that old API documentation is dead wrong; as I wrote (see above) the tan( ... ) method takes a number in radians and returns a dimensionless number. That atan( ... ) method works the other way around (as an inverse function should): it takes a dimensionless value and returns a number measured in radians. It's probably a copy/paste error ;)
kind regards,
JosBuild a wall around Donald Trump; I'll pay for it.
 08092011, 08:20 AM #12
Yikes!
You are 4 versions behind.
 08092011, 10:14 AM #13
A mathematical definition for tangent in Trigonometry:
The tangent of an angle is the opposite side over the adjacent side.
Therefore we can deduce that a tangent takes an angle and returns a unitless number.
Arctangent:
Arctangent is the inverse function of tangent.
Therefore the arctangent takes a unitless number and returns an angle.
In Java these angles have units of radians.If you aren't programming in Java, well that's just too bad.
I'd rather be using Ubuntu.
 08092011, 10:33 AM #14
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,402
 Blog Entries
 7
 Rep Power
 25
 04292012, 08:13 PM #15
Re: Why doesn't Math.tan() work?
Last edited by stchman; 04292012 at 08:15 PM.
If you aren't programming in Java, well that's just too bad.
I'd rather be using Ubuntu.
Similar Threads

Jar doesn't work
By mad72584 in forum New To JavaReplies: 35Last Post: 08072011, 05:22 PM 
why this doesn't work?
By hitesh_public in forum New To JavaReplies: 5Last Post: 08092010, 08:07 AM 
Can't get my date math to work
By pahiker in forum New To JavaReplies: 8Last Post: 07132010, 02:06 AM 
Why doesn't this work?
By Corder10 in forum New To JavaReplies: 1Last Post: 07042009, 10:33 PM 
my loop doesn't work.. pls help???
By ashton in forum New To JavaReplies: 5Last Post: 01162009, 09:24 AM
Bookmarks