cos()
Published Oct 26, 2023
Contribute to Docs
The cos()
function returns the cosine of an angle given in radians.
Syntax
$result = math.cos(angle);
result
: The variable to store the output of the cosine operation.
angle
: The angle in radians.
Example
The example below demonstrates the use of the math.cos()
function to find the cosine of a 45-degree angle.
local angle = (math.pi / 4) -- 45 degrees in radianslocal cosineOutput = math.cos(angle)print(cosineOutput)
This example will result in the following output:
0.70710678118655
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