math.sin

Shared

Returns the sine of an angle given in radians


Syntax

local result = math.sin(
    angle
)

Parameters

TypeNameDescription
numberangleAngle in radians

Returns

TypeNameDescription
numberresultSine of angle, in the range [-1, 1]

Examples

Sine of 0
local result = math.sin(0)

engine.print("info", result) -- 0.0
Sine of pi/2 is 1
local result = math.sin(math.pi / 2)

engine.print("info", result) -- 1.0
Sine of a 30 degree angle
local result = math.sin(math.rad(30))

engine.print("info", result) -- 0.5
Sine of a 90 degree angle
local result = math.sin(math.rad(90))

engine.print("info", result) -- 1.0
Animate vertical position with a sine wave
local elapsed = 0.5
local amplitude = 10
local frequency = 2
local pos_y = amplitude * math.sin(frequency * elapsed)

engine.print("info", pos_y) -- 8.4147
Generate a circular position
local angle = math.pi / 4
local radius = 5
local pos_x = radius * math.cos(angle)
local pos_y = radius * math.sin(angle)

engine.print("info", pos_x, pos_y) -- 3.5355  3.5355
Compute sine for each cardinal angle
for _, deg in ipairs({0, 90, 180, 270, 360}) do
    engine.print("info", deg, math.sin(math.rad(deg)))
end

On this page