🌐
W3Schools
w3schools.com › java › ref_math_atan2.asp
Java Math atan2() Method
Java Examples Java Videos Java Compiler Java Exercises Java Quiz Java Code Challenges Java Server Java Syllabus Java Study Plan Java Interview Q&A Java Certificate ... System.out.println(Math.atan2(0.5, 0.5)); System.out.println(Math.atan2(-0.5, -0.5)); System.out.println(Math.atan2(5, 5)); System.out.println(Math.atan2(10, 20)); System.out.println(Math.atan2(-5, -5)); System.out.println(Math.atan2(-10, 10));
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-lang-math-atan2-java
java.lang.Math.atan2() in Java - GeeksforGeeks
June 20, 2021 - atan2() is an inbuilt method in Java that is used to return the theta component from the polar coordinate.
Discussions

How does Math.atan2 work?
if I understood right this method returns result in radians. Like angle of 0 degrees is 0, angle of 180 is 3,14... This supposed to help you to convert coordinates from cartesian system (x, y) to polar coordinates (radius, angle) it can be really helpful in some cases. So that for point (0, 90) polar representation is like (90, 1.57) For some reason atan2 method gets arguments in reversed manner. Y then X. More on reddit.com
🌐 r/learnjava
2
4
March 29, 2021
math - Java a way to get from an angle the atan2 value (alpha)? - Stack Overflow
Now I want to convert the angle to the alpha value (atan2) is there a way how i can do that? More on stackoverflow.com
🌐 stackoverflow.com
Extremely Fast atan2 - Shared Code - JVM Gaming
Hello, I’ve just been looking around for a faster way to do Math.atan2(y,x) and I came across a number of methods. To compare them, I setup a simple JMH benchmark and accuracy test. Criticisms and new atan2 submissions are appreciated. Recommended implementation with lookup table: Icecore’s ... More on jvm-gaming.org
🌐 jvm-gaming.org
20
0
July 25, 2015
math - Java: Tangent method - Stack Overflow
Yes, you do indeed want atan, or sometimes, atan2. The difference between the two is that atan will fail under some circumstances when one of the side lengths are zero. While that may be unlikely for triangles, it is a possibility for some other, more general uses of atan. More on stackoverflow.com
🌐 stackoverflow.com
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › Math.html
Math (Java Platform SE 8 )
October 20, 2025 - public static double atan2(double y, double x) Returns the angle theta from the conversion of rectangular coordinates (x, y) to polar coordinates (r, theta). This method computes the phase theta by computing an arc tangent of y/x in the range of -pi to pi. Special cases: If either argument ...
🌐
Reddit
reddit.com › r/learnjava › how does math.atan2 work?
r/learnjava on Reddit: How does Math.atan2 work?
March 29, 2021 -

I've been calculating rotation needed between two 3d points, and I'm having some slight trouble.

You can use very basic sohcahtoa to find the angle needed between the two points by making a right triangle and just doing arctan of opposite/adjacent (the two sides). Now this only works if all of the values are positive, as, for example, arctan(-5/-4) == arctan(5/4). I do remember learning something about fixing this back when I learned about trig identities in school, and how to fix it, but my friend sent me some code, and he used Math.atan2 instead of tangent.

Now his code works perfectly, and was not too different from mine, and it really made me wonder what Math.atan2 does. I searched up on the internet, and didn't understand a word of the descriptions. Can someone show me what Math.atan2 is in normal math writing?

🌐
Stack Overflow
stackoverflow.com › questions › 70541352 › java-a-way-to-get-from-an-angle-the-atan2-value-alpha
math - Java a way to get from an angle the atan2 value (alpha)? - Stack Overflow
double dx = mx - px; double dy = my - py; double alpha = Math.atan2(dy, dx); float angle = (float) Math.toDegrees(alpha); angle += 10; Now I want to convert the angle to the alpha ...
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › java.lang.math.atan2
Math.Atan2(Double, Double) Method (Java.Lang) | Microsoft Learn
Microsoft makes no warranties, express or implied, with respect to the information provided here. Returns the angle theta from the conversion of rectangular coordinates (x, y) to polar coordinates (r, theta).
🌐
Programiz
programiz.com › java-programming › library › math › atan2
Java Math atan2()
class Main { public static void main(String[] args) { // two coordinates x and y double x = 3.7; double y = 6.45; // get angle θ double theta = Math.atan2(y, x); System.out.println(theta); // 1.0499821573815171 // convert into the degree System.out.println(Math.toDegrees(theta)); // 60.15954618200191 } }
🌐
Coderanch
coderanch.com › t › 375015 › java › atan-atan
what is the different between atan() and atan2()? (Java in General forum at Coderanch)
November 2, 2004 - Well, you could always read the API documentation! Basically, the difference between atan() and atan2() is that atan2() has a bigger range of return values. It can achieve this bigger range because it has more information to go on, from its two arguments, rather than the single argument of atan().
Find elsewhere
🌐
Vultr Docs
docs.vultr.com › java › standard-library › java › lang › Math › atan2
Java Math atan2() - Calculate Arc Tangent | Vultr Docs
November 22, 2024 - The atan2() function in Java's Math class offers a robust solution for calculating angles in radians between the x-axis and a point in any of the four quadrants. Its comprehensive handling of different coordinate signs and its straightforward ...
🌐
Oracle
docs.oracle.com › en › java › javase › 11 › docs › api › java.base › java › lang › Math.html
Math (Java SE 11 & JDK 11 )
January 20, 2026 - public static double atan2​(double y, double x) Returns the angle theta from the conversion of rectangular coordinates (x, y) to polar coordinates (r, theta). This method computes the phase theta by computing an arc tangent of y/x in the range of -pi to pi.
🌐
Codecademy
codecademy.com › docs › java › math methods › .atan2()
Java | Math Methods | .atan2() | Codecademy
August 24, 2022 - The Math.atan2() method returns the counterclockwise angle, in radians, between a (x,y) point and the positive x-axis. ... Looking for an introduction to the theory behind programming?
🌐
JVM Gaming
jvm-gaming.org › shared code
Extremely Fast atan2 - Shared Code - JVM Gaming
July 25, 2015 - Hello, I’ve just been looking around for a faster way to do Math.atan2(y,x) and I came across a number of methods. To compare them, I setup a simple JMH benchmark and accuracy test. Criticisms and new atan2 submissions are appreciated. Recommended implementation with lookup table: Icecore’s Recommended implementation without lookup table: Kappa’s Relevant data Current results: apache_atan2 : Average Error 0.00000 / Largest Error 0.00000 - Performance 367.945 ns/op default_a...
Top answer
1 of 4
8

Yes, you do indeed want atan, or sometimes, atan2. The difference between the two is that atan will fail under some circumstances when one of the side lengths are zero. While that may be unlikely for triangles, it is a possibility for some other, more general uses of atan. In addition, the atan function gives you an angle limited to the interval [-pi/2,pi/2]. So if you think about the atan function as a function of two inputs, (x,y), atan(y/x) will yield the same result as atan((-y)/(-x)). This is a serious flaw in some circumstances.

To solve these problems, the atan2 is defined such that it yields the correct result for all values of x and y, in any quadrant. One would use it as

atan2(oppositesidelength,adjacentsidelength)

to yield a consistent result.

Of course, for use in a non-degenerate triangle, the simple call to atan(opposite/adjacent) should be entirely adequate for your purposes.

2 of 4
2

Yep, you want atan, the arc tangent. This is the inverse of tangent; same thing with sin and arc sine, cosine and arc cosine, etc. These are alternative mathematical terminology for these functions' inverses.

Notice how atan returns angles from -π/2 to π/2, by the way. That's a hint that it's an inverse function (tangent takes angles and spits out ratios, arc tangent takes ratios and spits out angles). It is also important to recognize the restricted range. You won't necessarily get back your original angle, since tangents repeat every π radians (every 180°) — tan(π) = 0, but atan(0) = 0, not π.

🌐
Sarthaks eConnect
sarthaks.com › 3497170 › explain-java-math-atan2-method
Explain Java Math atan2() Method - Sarthaks eConnect | Largest Online Education Community
April 29, 2023 - LIVE Course for free · The atan2() method is a part of the java.lang.Math class in Java, and it is used to calculate the angle (in radians) between the positive x-axis and a point on a plane, with respect to the origin (0,0). This method takes ...
🌐
Tutorialspoint
tutorialspoint.com › java › lang › number_atan2.htm
Java - Math.atan2() Method
The Java Math atan2(double y,double x) converts rectangular coordinates (x, y) to polar (r, theta). This method computes the phase theta by computing an arc tangent of y/x in the range of -pi to pi. Special cases ?
🌐
Apache Commons
commons.apache.org › proper › commons-math › javadocs › api-3.6.1 › org › apache › commons › math3 › analysis › function › Atan2.html
Atan2 (Apache Commons Math 3.6.1 API)
java.lang.Object · org.apache.commons.math3.analysis.function.Atan2 · All Implemented Interfaces: BivariateFunction · public class Atan2 extends Object implements BivariateFunction · Arc-tangent function. Since: 3.0 · clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, ...
🌐
Kotlin
kotlinlang.org › api › core › kotlin-stdlib › kotlin.math › atan2.html
atan2 | Core API – Kotlin Programming Language
expect fun atan2(y: Double, x: Double): Double(source) Returns the angle theta of the polar coordinates (r, theta) that correspond to the rectangular coordinates (x, y) by computing the arc tangent of the value y / x; the returned value is an ...
🌐
Charlespetzold
charlespetzold.com › blog › 2008 › 09 › 180741.html
Charles Petzold: Atan2 and Exceptions (and why there aren’t any)
September 20, 2008 - The MSDN documentation for the ... states "If the first argument is positive zero and the second argument is positive, or the first argument is positive and finite and the second argument is positive infinity, then the result is positive zero" which I'm ...