sin()
Published Oct 17, 2023
Contribute to Docs
The sin()
function in Lua’s math library calculates the sine of an angle given in radians. The result is the ratio of two sides of a right-angled triangle: the length of the side opposite the given angle to the length of the hypotenuse.
Syntax
math.sin(angle)
angle
: The angle in radians.
Example
In this example, math.sin()
calculates the sine of a 90 degree angle (π/2 radians).
local angle = math.pi / 2local answer = math.sin(angle)local output = string.format("The sine of %.4f is approximately %.0f", angle, answer)print(output)
This is the resulting output:
The sine of 1.5708 is approximately 1
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Lua on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Free course
Learn Lua
Learn the basics of Lua, a general-purpose programming language used for building games, web apps, and developer tools.Beginner Friendly4 hours