Unofficial LSL Reference

[[functions:llcos]]


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

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

functions:llcos [2014-05-15 08:02 SLT]
sei [Short examples] anti-clockwise -> counter-clockwise
functions:llcos [2015-02-04 08:22 SLT] (current)
sei pinf minf nan
Line 1: Line 1:
 +$nav
 ===== Function: llCos ===== ===== Function: llCos =====
  
Line 10: Line 11:
  
 === arg === === arg ===
-Angle whose cosine is to be found, in radians.+A $lty[float] with the angle whose cosine is to be found, in radians.
  
-===== Result ​=====+===== Return value =====
  
-Cosine ​of the argument.+A $lty[float] with the cosine ​of the argument.
  
 ===== Notes ===== ===== Notes =====
  
-  * Inputs of **-Inf****Inf** ​and **NaN** ​result in **NaN** (Not a Number)+  * Inputs of $pinf$minf and $nan result in $nan
-  * If the angle is otherwise not between -9.22337e18 and 9.22337e18, the argument is returned unchanged.+  * If the angle is otherwise not between ​approx. ​-9.22337e18 and 9.22337e18, the argument is returned unchanged.
   * Otherwise, the return value is always between -1 and 1.   * Otherwise, the return value is always between -1 and 1.
  
Line 28: Line 29:
 F = llCos(1); // Sets F to approx. 0.540302, because that's the cosine of 1 radian. F = llCos(1); // Sets F to approx. 0.540302, because that's the cosine of 1 radian.
 F = llCos(-1); // Sets F to approx. 0.540302 too, F = llCos(-1); // Sets F to approx. 0.540302 too,
-               //​because the cosine of -1 radian equals the cosine of 1 radian.+               // because the cosine of -1 radian equals the cosine of 1 radian.
 F = llCos(0); // Sets F to 1, because that's the cosine of 0. F = llCos(0); // Sets F to 1, because that's the cosine of 0.
 F = llCos(PI); // Sets F to -1, which is the cosine of PI. F = llCos(PI); // Sets F to -1, which is the cosine of PI.
 F = llCos(1e20); ​ // Sets F to 1e20 because 1e20 is returned unchanged. F = llCos(1e20); ​ // Sets F to 1e20 because 1e20 is returned unchanged.
-rotation rot; 
-float a = 30*DEG_TO_RAD;​ 
-rot = <​llSin(a/​2),​ 0, 0, llCos(a/​2)>;​ // Sets rot to a rotation over the X axis by 30° counter-clockwise. 
-rot = <​-llSin(a/​2),​ 0, 0, llCos(a/​2)>;​ // Sets rot to a rotation over the X axis by 30° clockwise. 
-rot = <0, llSin(a/2), 0, llCos(a/​2)>;​ // Sets rot to a rotation over the Y axis by 30° counter-clockwise. 
-rot = <0, 0, llSin(a/2), llCos(a/​2)>;​ // Sets rot to a rotation over the Z axis by 30° counter-clockwise. 
-</​code>​ 
- 
-Note: the last four examples are faster than their equivalents using [[llEuler2Rot]],​ which are: 
-<code lsl2> 
-rot = llEuler2Rot(<​30,​0,​0>​*DEG_TO_RAD);​ 
-rot = llEuler2Rot(<​-30,​0,​0>​*DEG_TO_RAD);​ 
-rot = llEuler2Rot(<​0,​30,​0>​*DEG_TO_RAD);​ 
-rot = llEuler2Rot(<​0,​0,​30>​*DEG_TO_RAD);​ 
 </​code>​ </​code>​
  
 ===== Complete examples ===== ===== Complete examples =====
  
-llCos is very frequently used together with [[llSin]], as llCos gives the X component and llSin the Y component of a unit vector at the given angle.+$fn[llCosis very frequently used together with $lfn[llSin], as $fn[llCosgives the X component and $fn[llSinthe Y component of a unit 2D vector at the given angle.
  
 <file lsl2 llSin-llCos-example.lsl>​ <file lsl2 llSin-llCos-example.lsl>​
Line 69: Line 56:
 } }
 </​file>​ </​file>​
 +
 +The opposite calculation,​ i.e. finding the angle of a 2D vector, can be performed with $lfn[llAtan2].
  
 ===== See also ===== ===== See also =====
  
 === Related trigonometric functions === === Related trigonometric functions ===
-  * [[llSin]] calculates the sine of the argument. +  * $lfn[llSin] calculates the sine of the argument. 
-  * [[llAcos]] calculates the inverse cosine of the argument.+  * $lfn[llAcos] calculates the inverse cosine of the argument
 +  * $lfn[llAtan2] calculates the angle of a 2D vector.
  
 === Other trigonometric functions === === Other trigonometric functions ===
-  * [[llAsin]] calculates the inverse sine of the argument. +  * $lfn[llAsin] calculates the inverse sine of the argument. 
-  * [[llTan]] calculates the tangent of the argument. +  * $lfn[llTan] calculates the tangent of the argument. 
-  * [[llAtan2]] calculates the angle of a 2D vector.+ 
 +=== Related information === 
 +  * $lty[floattype and associated caveats and limitations.