Lua tan()

EddyCkan's avatar
Published Oct 14, 2023
Contribute to Docs

In Lua, the math.tan() function is a standard mathematical function that is part of the Lua math library. It is used to calculate the tangent of a given angle.

Note: math.tan() expects the input angle value to be in radians. If an angle’s value is in degrees, it can be converted into radians using the math.pi constant in Lua and the following formula: radians = degrees * (math.pi / 180)

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn the basics of Lua, a general-purpose programming language used for building games, web apps, and developer tools.
    • Beginner Friendly.
      4 hours

Syntax

math.tan(myangle)

Example

To find the tangent of an angle in degrees, first convert it into radians, and then pass the value to the math.tan() function, or simply pass in the radian value:

local angle = 45 * ( math.pi / 180 )
print(math.tan(angle))
print(math.tan(math.pi / 6))

This results in the following output:

1.0
0.57735026918963

All contributors

Contribute to Docs

Learn Lua on Codecademy

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn the basics of Lua, a general-purpose programming language used for building games, web apps, and developer tools.
    • Beginner Friendly.
      4 hours