• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

What is Math.atan() returning?

 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, according to the JavaDoc, the result is an angle in Radians.

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

Henry
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can also use Math.toDegrees() to convert from radians to degrees.
 
Ranch Hand
Posts: 341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
java doc 1.4.2



atan
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.

Parameters:
a - the value whose arc tangent is to be returned.
Returns:
the arc tangent of the argument.

 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!!!
:-)
 
dave taubler
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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!
 
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Won't you please? Please won't you be my neighbor? - Fred Rogers. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic