util.math.rad

Shared

Converts an angle from degrees to radians


Syntax

local result = util.math.rad(
    angle
)

Parameters

TypeNameDescription
floatangleAngle in degrees to convert

Returns

TypeNameDescription
floatresultEquivalent angle in radians

Examples

Convert 180 degrees to radians
local result = util.math.rad(180)

core.engine.print("info", result) -- 3.1415926535898
Convert 90 degrees to radians
local result = util.math.rad(90)

core.engine.print("info", result) -- 1.5707963267949
Convert 0 degrees to radians
local result = util.math.rad(0)

core.engine.print("info", result) -- 0.0
Convert 360 degrees to 2*pi
local result = util.math.rad(360)

core.engine.print("info", result) -- 6.2831853071796
Pass a degree value directly to sin
local result = util.math.sin(util.math.rad(30))

core.engine.print("info", result) -- 0.5
Rotate through 8 cardinal directions
for i = 0, 7 do
    local deg = i*45
    local rad = util.math.rad(deg)
    core.engine.print("info", deg, rad)
end
Verify rad and deg are inverses
local original = util.math.pi/3
local result = util.math.rad(util.math.deg(original))

core.engine.print("info", result) -- 1.0471975511966

On this page