$nav ===== Function: llAtan2 ===== float llAtan2(float y, float x) Return the angle of the 2D vector given by x and y. Note that the arguments are in reverse order: the first is y, the second is x. ===== Parameters ===== === y === The y component of the 2D vector. === x === The x component of the 2D vector. ===== Return value ===== $lty[Float] number with the angle of the vector. ===== Notes ===== * If both components are zero, the result is zero. * The result is always between -$lct[PI] and $ct[PI], except if one of the inputs is $nan, in which case it returns $nan as well. * This function distinguishes zero and minus zero, in that e.g. llAtan2(-0.0, -1) gives -$ct[PI], not $ct[PI]. * The name and order of parameters of this function come from the fact that the angle of a 2D vector with a nonzero x coordinate is given by the arctangent (inverse tangent) of y/x. The order y, x is customarily used in many programming languages. * The convention in navigation is that zero degrees is North (or forward, if expressing a relative angle), and the angle grows clockwise, so 90 degrees is East (or right), and so on. This differs from the convention in mathematics, where zero degrees is East, etc. To use the navigation convention, only "un-inverting" x and y is needed, e.g. ''llAtan2(1, 2)'' is the angle of the vector (1, 2) expressed with this convention. ===== Short examples ===== float angle; angle = llAtan2(0, 1); // Sets angle to 0 because that's the angle of the vector (1, 0). angle = llAtan2(-3, 0); // Sets angle to -PI_BY_TWO, because that's the angle of the vector (0, -3). angle = llAtan2(1.3, 2.3); // Sets angle to approx. 0.514451 as that's the angle of the vector (2.3, 1.3) angle = llAtan2(0, 0); // Sets angle to 0. angle = llAtan2(0, -1); // Sets angle to PI, because that's the angle of the vector (-1, 0). angle = llAtan2(-0.0, -2); // Sets angle to -PI. angle = llAtan2((float)"NaN", 0); // Sets angle to NaN (Not a Number) because one input is NaN. ===== Complete examples ===== The following example will output the heading of a prim, in degrees: default { state_entry() { vector fwd = <1,0,0>*llGetLocalRot(); float heading = llAtan2(fwd.y, fwd.x); llOwnerSay("Heading=" + (string)(heading * RAD_TO_DEG) + "°"); } } ===== See also ===== * $lfn[llTan] calculates the tangent of the argument. * $lfn[llAsin] calculates the inverse sine of the argument. * $lfn[llSin] calculates the sine of the argument. * $lfn[llAcos] calculates the inverse cosine of the argument. * $lfn[llCos] calculates the cosine of the argument. * $lfn[llAngleBetween] calculates the angle between two rotations. * $lfn[llRot2Angle] takes the angle part of a $lty[rotation]. * Other $lfn[math/] functions.