math.sin
Shared
Returns the sine of an angle given in radians
Syntax
local result = math.sin(
angle
)Parameters
| Type | Name | Description |
|---|---|---|
number | angle | Angle in radians |
Returns
| Type | Name | Description |
|---|---|---|
number | result | Sine of angle, in the range [-1, 1] |
Examples
local result = math.sin(0)
engine.print("info", result) -- 0.0local result = math.sin(math.pi / 2)
engine.print("info", result) -- 1.0local result = math.sin(math.rad(30))
engine.print("info", result) -- 0.5local result = math.sin(math.rad(90))
engine.print("info", result) -- 1.0local elapsed = 0.5
local amplitude = 10
local frequency = 2
local pos_y = amplitude * math.sin(frequency * elapsed)
engine.print("info", pos_y) -- 8.4147local 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.5355for _, deg in ipairs({0, 90, 180, 270, 360}) do
engine.print("info", deg, math.sin(math.rad(deg)))
end