Math.atan()

Math.atan() 静态方法返回数字的反正切值(以弧度为单位),即

¥The Math.atan() static method returns the inverse tangent (in radians) of a number, that is

𝙼𝚊𝚝𝚑.𝚊𝚝𝚊𝚗 ( 𝚡 ) = arctan ( x ) = the unique  y [ π 2 , π 2 ]  such that  tan ( y ) = x \mathtt{\operatorname{Math.atan}(x)} = \arctan(x) = \text{the unique } y \in \left[-\frac{\pi}{2}, \frac{\pi}{2}\right] \text{ such that } \tan(y) = x

Try it

语法

¥Syntax

js
Math.atan(x)

参数

¥Parameters

x

一个号码。

返回值

¥Return value

反正切( - π 2 </ 之间的弧度角 mrow><注释编码="TeX">-\frac{\pi}{2}</注释></语义></数学> 和 <数学><语义> π 2< /mfrac><注释编码="TeX">\frac{\pi}{2}</注释></语义></数学>,包含) x。如果 xInfinity,则返回 π 2 \frac{\pi}{2}</ 语义></数学>。如果 x-Infinity,则返回 - π 2 <注释编码="TeX">-\frac{\pi}{2}</注释></语义></数学>。

¥The inverse tangent (angle in radians between - π 2 -\frac{\pi}{2} and π 2 \frac{\pi}{2} , inclusive) of x. If x is Infinity, it returns π 2 \frac{\pi}{2} . If x is -Infinity, it returns - π 2 -\frac{\pi}{2} .

描述

¥Description

因为 atan()Math 的静态方法,所以你始终将其用作 Math.atan(),而不是用作你创建的 Math 对象的方法(Math 不是构造函数)。

¥Because atan() is a static method of Math, you always use it as Math.atan(), rather than as a method of a Math object you created (Math is not a constructor).

示例

¥Examples

使用 Math.atan()

¥Using Math.atan()

js
Math.atan(-Infinity); // -1.5707963267948966 (-π/2)
Math.atan(-0); // -0
Math.atan(0); // 0
Math.atan(1); // 0.7853981633974483  (π/4)
Math.atan(Infinity); // 1.5707963267948966  (π/2)

// The angle that the line (0,0) -- (x,y) forms with the x-axis in a Cartesian coordinate system
const theta = (x, y) => Math.atan(y / x);

请注意,你可能希望避免使用 theta 函数并使用 Math.atan2(),它具有更宽的范围(在 -π 和 π 之间),并避免在 x0 等情况下输出 NaN

¥Note that you may want to avoid the theta function and use Math.atan2() instead, which has a wider range (between -π and π) and avoids outputting NaN for cases such as when x is 0.

规范

Specification
ECMAScript Language Specification
# sec-math.atan

¥Specifications

浏览器兼容性

BCD tables only load in the browser

¥Browser compatibility

也可以看看