math.tan

Shared

Returns the tangent of an angle given in radians


Syntax

local result = math.tan(
    angle
)

Parameters

TypeNameDescription
numberangleAngle in radians

Returns

TypeNameDescription
numberresultTangent of angle

Examples

Tangent of 0
local result = math.tan(0)

engine.print("info", result) -- 0.0
Tangent of 45 degrees is 1
local result = math.tan(math.rad(45))

engine.print("info", result) -- 1.0
Tangent of a negative angle
local result = math.tan(math.rad(-45))

engine.print("info", result) -- -1.0
Calculate slope from an angle
local angle_deg = 30
local slope = math.tan(math.rad(angle_deg))

engine.print("info", slope) -- 0.57735
Compute height from distance and elevation angle
local distance = 100
local elevation_deg = 30
local height = distance * math.tan(math.rad(elevation_deg))

engine.print("info", height) -- 57.735
Verify tan equals sin over cos
local angle = math.rad(60)
local result = math.sin(angle) / math.cos(angle)

engine.print("info", result, math.tan(angle)) -- 1.7320  1.7320

On this page