Unofficial LSL Reference

[[functions:llacos]]


Unofficial LSL reference

User Tools

Login

You are currently not logged in! Enter your authentication credentials below to log in. You need to have cookies enabled to log in.

Login

Forgotten your password? Get a new one: Set new password

Function: llAcos

float llAcos(float arg)

Return the inverse cosine of the argument, in radians. The inverse cosine (also known as arccosine) is the angle whose cosine is the given argument.

Parameters

arg

Number whose inverse cosine is to be found.

Return value

Float number with the angle in radians that is the inverse cosine of the argument.

Notes

  • The range of arg must be between -1 and 1, because the cosine of any angle can't be outside that range.
  • The result is always between 0 and PI, or NaN if the argument is out of the valid range.

Short examples

float angle;
angle = llAcos(1); // Sets angle to 0, because the cosine of 0 is 1.
angle = llAcos(0); // Sets angle to PI_BY_TWO, because the cosine of PI/2 is 0.
angle = llAcos(-1); // Sets angle to PI, because the cosine of PI is -1.
angle = llAcos(0.31); // Sets angle to approximately 1.255603 (the cosine of that is 0.31)

angle = llAcos(2);  // Under Mono, sets angle to NaN (Not a Number),
                    // because there's no number whose cosine is 2.
                    // Crashes with a math error under LSO.

Complete examples

A rotation can be expressed by an axis and an angle. This example illustrates how to use llAcos to obtain the angle component of a rotation, assumed it's normalized (most LSL functions return normalized rotations). If the rotation is not guaranteed to be normalized, use llRot2Angle instead.

llAcos-example.lsl
default
{
    state_entry()
    {
        rotation rot = llGetLocalRot();
        llOwnerSay("The angle of rotation of this prim is " + (string)(2*llAcos(rot.s)) + " radians.");
    }
}

See also

  • llCos calculates the cosine of the argument.
  • llAsin calculates the inverse sine of the argument.
  • llSin calculates the sine of the argument.
  • llAtan2 calculates the angle of a 2D vector.
  • llTan calculates the tangent of the argument.
  • Other math functions.