The math.asin() function in lua returns the inverse sine (in radians) of a number. That is:
∀ x ∊ [-1, 1], math.asin(x) = arcsin(x) = the unique y ∊ [-π/2, π/2] such that sin(y) = x.
Syntax
math.asin(x)
Parameters
x
A number between-1and1(inclusive), representing the sine value of an angle.
Return value
The inverse sine of x, expressed as an angle in radians between -π/2 and π/2 (inclusive). If x is less than -1 or greater than 1, the function returns nil or may trigger an error, as the value is undefined in these cases.
Description
Because math.asin() is a static function, it is always used as math.asin(), rather than as a method of a lua object. This function is commonly used to compute the angle corresponding to a given sine value.
Examples
Using math.asin()
print(math.asin(-1)) -- -1.5707963267949 (-π/2)
print(math.asin(0)) -- 0
print(math.asin(0.5)) -- 0.5235987755983 (π/6)
print(math.asin(1)) -- 1.5707963267949 (π/2)
Handling out-of-range values
If the input value is outside the range [-1, 1], the result is undefined, and an error or nil may occur.
-- Correct usage:
print(math.asin(0.75)) -- A valid angle in radians
-- Incorrect usage:
-- print(math.asin(2)) -- Error: argument out of range
See also
math.acos()math.atan()math.atan2()math.cos()math.sin()math.tan()