The math.rad() function converts an angle from degrees to radians.

Syntax

math.rad(x)

Parameters

  • x: The angle in degrees.

Return Value

The function returns the equivalent angle in radians.

Description

The math.rad function is useful for converting degrees to radians, which is often required in trigonometric functions in lua's math library, as these functions expect angles to be in radians.

Examples

Using math.rad

local degrees = 180
local radians = math.rad(degrees)
print(radians) -- Output: 3.141592653589793

Converting different angles

print(math.rad(0))    -- Output: 0
print(math.rad(90))   -- Output: 1.5707963267948966
print(math.rad(360))  -- Output: 6.283185307179586

See also

  • math.deg: Converts an angle from radians to degrees.

Was this page helpful?

Table of Contents