math.deg

Shared

Converts an angle from radians to degrees


Syntax

local result = math.deg(
    angle
)

Parameters

TypeNameDescription
numberangleAngle in radians to convert

Returns

TypeNameDescription
numberresultEquivalent angle in degrees

Examples

Convert pi radians to degrees
local result = math.deg(math.pi)

engine.print("info", result) -- 180.0
Convert pi/2 to degrees
local result = math.deg(math.pi / 2)

engine.print("info", result) -- 90.0
Convert 0 radians to degrees
local result = math.deg(0)

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

engine.print("info", result) -- 360.0
Convert an atan2 result to readable degrees
local angle = math.atan(1, 0)
local degrees = math.deg(angle)

engine.print("info", degrees) -- 90.0
Print common radian values in degrees
for _, rad in ipairs({0, math.pi/6, math.pi/4, math.pi/3, math.pi/2}) do
    engine.print("info", math.deg(rad))
end

--[[
Output:
0.0
30.0
45.0
60.0
90.0
]]
Verify deg and rad are inverses
local original = 135
local result = math.deg(math.rad(original))

engine.print("info", result) -- 135.0

On this page