Baseline Widely available
Math.atan2()
ì ì ë©ìëë Math.atan2(y, x)
ì ëí´ ìì xì¶ê³¼ (0, 0)ìì (x, y)ì ê¹ì§ì ê´ì ì¬ì´ì íë©´ ê°ë(ë¼ëì ë¨ì)를 ë°íí©ëë¤.
function calcAngleDegrees(x, y) {
return (Math.atan2(y, x) * 180) / Math.PI;
}
console.log(calcAngleDegrees(5, 5));
// Expected output: 45
console.log(calcAngleDegrees(10, 10));
// Expected output: 45
console.log(calcAngleDegrees(0, 10));
// Expected output: 90
구문 매ê°ë³ì
y
ì ì yì¢í.
x
ì ì 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()
ë - Ï 2 -\frac{\pi}{2} ë³´ë¤ ìê±°ë Ï 2 \frac{\pi}{2} ë³´ë¤ í° ê°ë를 ì¶ë ¥í©ëë¤.
atan2()
ë Math
ì ì ì ë©ìëì´ë¯ë¡, ìì±í Math
ê°ì²´ì ë©ìëê° ìëë¼ íì Math.atan2()
ë¡ ì¬ì©í©ëë¤(Math
ë ìì±ìê° ìëëë¤).
Math.atan2(90, 15); // 1.4056476493802699
Math.atan2(15, 90); // 0.16514867741462683
Math.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 |ëª ì¸ì ë¸ë¼ì°ì í¸íì± ê°ì´ 보기
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4