aspose file tools
The moose likes Java in General and the fly likes What is Math.atan() returning? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "What is Math.atan() returning?" Watch "What is Math.atan() returning?" New topic

What is Math.atan() returning?

dave taubler
Ranch Hand

Joined: May 15, 2001
Posts: 132
I am trying to simply find the angle between two points. I'm trying to get the arc tangent to derive the angle, but Math.atan() doesn not seem to return an angle of any sort. I've reduce my code to a simple example:

double distanceAngle = Math.atan(0.2455);
System.out.println("angle = " + distanceAngle);

that prints:

angle = 0.24073890523107128

If I go to any calculator and get the arc tangent of 0.2455, I get 13.79 degrees, which is the angle I am looking for. So......... does anyone know what Math.atan() is returning?

Dave Taubler<br />Specializing in <a href="" target="_blank" rel="nofollow">Java and Web Development</a>
Henry Wong

Joined: Sep 28, 2004
Posts: 19235

Well, according to the JavaDoc, the result is an angle in Radians.

To convert Radians to Degrees, multiply by 180 and divide by PI.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
You can also use Math.toDegrees() to convert from radians to degrees.

"I'm not back." - Bill Harding, Twister
Surasak Leenapongpanit
Ranch Hand

Joined: May 10, 2002
Posts: 341
java doc 1.4.2

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 zero, then the result is a zero with the same sign as the argument.
A result must be within 1 ulp of the correctly rounded result. Results must be semi-monotonic.

a - the value whose arc tangent is to be returned.
the arc tangent of the argument.
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11574

Here's the link you need to the API. I'd bookmark this site, and refer to it frequently. It will answer many of the question like this you may have, and probably be faster than posting here. But don't hesitate to ask here when you can't find the answer!!!

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
dave taubler
Ranch Hand

Joined: May 15, 2001
Posts: 132

Thanks to everyone who replied, I do appreciate it. The reason I wrote is that I *did* go through the JavaDocs, and they were no help (even Surasak Leenapongpanit's reposting of the atan() API says nothing about radians); I Googled for about half an hour as well, to no avail. Believe me, I do all the research I reasonably can before posting!
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
In the version of the API JavaDocs that I have (1.4.2, I think), it does mention radians in many of the math functions, but not in atan(). It does give a clue by saying that the result of atan() will be between plus and minus pi/2, though, which is a hint at radians.

I reckon the person who wrote the docs was a mathematician or engineer for whom radians would be the "obvious" representation. But degrees are still the most common representation of angles, for most people.

Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
I agree. Here's the link:
subject: What is Math.atan() returning?