MySQL ATAN2() Function: Calculate an angle from two coordinates

ATAN2(y, x) returns an angle in radians using the signs of both coordinates, helping distinguish quadrants.

ATAN2(): Quick SQL Example

Run this SELECT query directly in MySQL or phpMyAdmin. It uses fixed inputs so you can verify the result without creating a table.

SELECT ROUND(DEGREES(ATAN2(1, 1)), 2) AS angle_degrees;
angle_degrees
45.00
On this page — Show page sectionsHide page sections

More SQL Examples and Explanations

ATAN2(Y,X) returns the arc tangent using both argument signs to determine the correct quadrant. It is related to ATAN(Y/X), but preserves quadrant information.

SELECT ATAN2(8, 6); -- Output: 0.927295218001612
SELECT ATAN2(0.1, 0.3); -- Output: 0.321750554396642
SELECT ATAN2(0, 0); -- Output: 0

Using ROUND() with ATAN2()

SELECT ROUND(ATAN2(5, 6), 2); -- Output: 0.69
SELECT ROUND(ATAN2(-3, -8), 2); -- Output: -2.78
SELECT ROUND(ATAN2(9, -15), 2); -- Output: 2.60

Syntax

SELECT ATAN2(Y, X);

How to Interpret the Result

The order is y first, x second. Reversing the arguments can change the angle.

Common Question

How is ATAN2() different from ATAN()?
ATAN2(y, x) uses both coordinate signs; ATAN(y/x) does not retain the same quadrant information.

↑ Back to top




Subscribe to our YouTube Channel here



plus2net.com




SQL Video Tutorials










✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer