math.atan
Shared
Returns the arc tangent of a value in radians, using both components to determine the correct quadrant
Syntax
local result = math.atan(
vertical,
horizontal = 1
)Parameters
| Type | Name | Description |
|---|---|---|
number | vertical | Vertical component (or the sole value when horizontal is omitted) |
number | horizontal | Horizontal component - used for two-argument atan2 behavior |
Returns
| Type | Name | Description |
|---|---|---|
number | result | Arc tangent of vertical/horizontal in radians, in the range [-pi, pi] |
Examples
local result = math.atan(1)
engine.print("info", result) -- 0.78539816339745local result = math.atan(0)
engine.print("info", result) -- 0.0local result = math.deg(math.atan(1, 1))
engine.print("info", result) -- 45.0local result = math.deg(math.atan(0, -1))
engine.print("info", result) -- 180.0local dir_x, dir_y = 3, -3
local angle_deg = math.deg(math.atan(dir_y, dir_x))
engine.print("info", angle_deg) -- -45.0local x1, y1 = 0, 0
local x2, y2 = 5, 5
local angle_deg = math.deg(math.atan(y2 - y1, x2 - x1))
engine.print("info", angle_deg) -- 45.0local angle = math.pi / 4
local result = math.atan(math.tan(angle))
engine.print("info", result) -- 0.78539816339745