This page was translated from English by the community.Learn more and join the MDN Web Docs community.
Math.atan2()
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015년 7월.
Math.atan2() 정적 메서드는Math.atan2(y, x)에 대해 양의 x축과 (0, 0)에서 (x, y)점까지의 광선 사이의 평면 각도(라디안 단위)를 반환합니다.
In this article
시도해 보기
function calcAngleDegrees(x, y) { return (Math.atan2(y, x) * 180) / Math.PI;}console.log(calcAngleDegrees(5, 5));// Expected output: 45console.log(calcAngleDegrees(10, 10));// Expected output: 45console.log(calcAngleDegrees(0, 10));// Expected output: 90구문
Math.atan2(y, x)매개변수
반환 값
양의 x축과 (0, 0)에서 (x, y) 지점까지의 광선 사이의 각도(-π와 π 사이, 포함)를 라디안 단위로 표시합니다.
설명
Math.atan2() 메서드는 양수 x축과 점(x, y) 사이의 시계 반대 방향 각도 θ를 라디안 단위로 측정합니다. 이 함수의 인수는 y 좌표를 먼저 전달하고 x 좌표를 두 번째로 전달합니다.

Math.atan2()는 별도의x 및y 인수를 전달하는 반면,Math.atan()은 이 두 인수의 비율을 전달합니다. 다음과 같은 경우Math.atan2(y, x)는Math.atan(y / x)와 다릅니다.
x | y | Math.atan2(y, x) | Math.atan(y / x) |
|---|---|---|---|
Infinity | Infinity | π / 4 | NaN |
Infinity | -Infinity | -π / 4 | NaN |
-Infinity | Infinity | 3π / 4 | NaN |
-Infinity | -Infinity | -3π / 4 | NaN |
| 0 | 0 | 0 | NaN |
| 0 | -0 | -0 | NaN |
< 0 (including-0) | 0 | π | 0 |
< 0 (including-0) | -0 | -π | 0 |
-Infinity | > 0 | π | -0 |
| -0 | > 0 | π / 2 | -π / 2 |
-Infinity | < 0 | -π | 0 |
| -0 | < 0 | -π / 2 | π / 2 |
또한 두 번째 및 세 번째 사분면(x < 0)에 있는 점의 경우Math.atan2()는보다 작거나보다 큰 각도를 출력합니다.
atan2()는Math의 정적 메서드이므로, 생성한Math 객체의 메서드가 아니라 항상Math.atan2()로 사용합니다(Math는 생성자가 아닙니다).
예제
>Math.atan2() 사용하기
Math.atan2(90, 15); // 1.4056476493802699Math.atan2(15, 90); // 0.16514867741462683Math.atan2(y, x) 과 Math.atan(y / x) 의 차이
아래 스크립트는Math.atan2(y, x)과Math.atan(y / x)의 차이를 출력합니다.
const formattedNumbers = new Map([ [-Math.PI, "-π"], [(-3 * Math.PI) / 4, "-3π/4"], [-Math.PI / 2, "-π/2"], [-Math.PI / 4, "-π/4"], [Math.PI / 4, "π/4"], [Math.PI / 2, "π/2"], [(3 * Math.PI) / 4, "3π/4"], [Math.PI, "π"], [-Infinity, "-∞"], [Infinity, "∞"],]);function format(template, ...args) { return String.raw( { raw: template }, ...args.map((num) => (Object.is(num, -0) ? "-0" : (formattedNumbers.get(num) ?? String(num)) ).padEnd(5), ), );}console.log(`| x | y | atan2 | atan ||-------|-------|-------|-------|`);for (const x of [-Infinity, -1, -0, 0, 1, Infinity]) { for (const y of [-Infinity, -1, -0, 0, 1, Infinity]) { const atan2 = Math.atan2(y, x); const atan = Math.atan(y / x); if (!Object.is(atan2, atan)) { console.log(format`| ${x} | ${y} | ${atan2} | ${atan} |`); } }}출력 결과는 아래와 같습니다.
| x | y | atan2 | atan ||-------|-------|-------|-------|| -∞ | -∞ | -3π/4 | NaN || -∞ | -1 | -π | 0 || -∞ | -0 | -π | 0 || -∞ | 0 | π | -0 || -∞ | 1 | π | -0 || -∞ | ∞ | 3π/4 | NaN || -1 | -∞ | -π/2 | π/2 || -1 | -1 | -3π/4 | π/4 || -1 | -0 | -π | 0 || -1 | 0 | π | -0 || -1 | 1 | 3π/4 | -π/4 || -1 | ∞ | π/2 | -π/2 || -0 | -∞ | -π/2 | π/2 || -0 | -1 | -π/2 | π/2 || -0 | -0 | -π | NaN || -0 | 0 | π | NaN || -0 | 1 | π/2 | -π/2 || -0 | ∞ | π/2 | -π/2 || 0 | -0 | -0 | NaN || 0 | 0 | 0 | NaN || ∞ | -∞ | -π/4 | NaN || ∞ | ∞ | π/4 | NaN |
명세서
| Specification |
|---|
| ECMAScript® 2026 Language Specification> # sec-math.atan2> |