Differences

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

Link to this comparison view

wiki:scripting_portal:lsl_functions:llatan2 [2018/11/20 17:21]
Royale Mobian created
wiki:scripting_portal:lsl_functions:llatan2 [2019/07/19 21:55] (current)
Royale Mobian
Line 1: Line 1:
-====== ​llAtan ​====== +====== ​llAtan2 ​====== 
-===== Introduction =====+**[[wiki:​scripting_portal:​lsl_functions|Function]]:​ [[wiki:​scripting_portal:​lsl_types:​float|float]] llAtan2( [[wiki:​scripting_portal:​lsl_types:​float|float]] y, [[wiki:​scripting_portal:​lsl_types:​float|float]] x );** 
 +Returns a float that is the [[http://​en.wikipedia.org/​wiki/​Atan2|arctangent2]] of **y**, **x**. 
 +  * float y  
 +  * float x
  
 +Similar to the [[http://​en.wikipedia.org/​wiki/​Inverse_trigonometric_functions|arctangent]](**y**/​**x**) except it utilizes the signs of **x** & **y** to determine the quadrant and avoids division by zero. 
  
-==== Example use cases: ​====+===== Specification ​===== 
 +If **** is positive zero and... 
 +  * **y** is zero, **zero** is returned. 
 +  * **y** is positive, **PI/2** is returned. 
 +  * **y** is negative, **-PI/2** is returned. 
 +If **x** is negative zero and... 
 +  * **y** is positive zero, **PI** is returned. 
 +  * **y** is negative zero, **-PI** is returned. 
 +  * **y** is positive, **PI/2** is returned. 
 +  * **y** is negative, **-PI/2** is returned. 
 +Or 
 +<code ossl> 
 +if((string)x != (string)0.0 && y == 0.0)//​negative zero 
 +    return PI * ~-2*((string)y != (string)0.0));​ 
 +return ((y > 0) - (y < 0)) * PI_BY_TWO;​ 
 +</​code>​ 
 +The returned value is in the range [-[[wiki:​scripting_portal:​lsl_functions:​ll_constants:​pi|PI]],​ PI].
  
 +===== Examples =====
 +<code ossl>
 +default
 +{
 +  state_entry()
 +  {
 +    float num1 = llFrand(100.0);​
 +    float num2 = llFrand(100.0);​
 + 
 +    llOwnerSay("​y = " + (string)num1);​
 +    llOwnerSay("​x = " + (string)num2);​
 + 
 +    llOwnerSay("​The arctangent of y divided by x is " + (string)llAtan2(num1,​ num2));
 +  }
 +}
 +</​code>​
 +<code ossl>
 +//Function with input of a vector determining the position of a target and returning
  
 +//a string with the literal compass-direction of that target towards your position
 +//by Ramana Sweetwater @ Second Life 2009/01, any use allowed license :-)
 +//corrected by Patrick Muggins @ Second Life
 + 
 +string compass (vector target) ​
 +{
  
-===== Examples =====+   ​vector source ​llGetPos();​ 
 +   list DIRS =["​W","​NW","​N","​NE","​E","​SE","​S","​SW","​W"​];​ 
 +   ​integer index llCeil(3.5 - (4 * llAtan2(target.y - source.y, target.x - source.x) / PI)); 
 +   ​return llList2String(DIRS,​ index);
  
-<code ossl> 
  
 +}
 </​code>​ </​code>​
 +
 +===== See Also =====
 +==== Functions ====
 +  * [[wiki:​scripting_portal:​lsl_functions:​llSin|llSin]] [[wiki:​scripting_portal:​lsl_functions:​llAsin|llAsin]] - sine & inverse Sine 
 +  * [[wiki:​scripting_portal:​lsl_functions:​llCos|llCos]] [[wiki:​scripting_portal:​lsl_functions:​llAcos|llAcos]] – cosine & inverse cosine
 +  * [[wiki:​scripting_portal:​lsl_functions:​llTan|llTan]] – tangent
 +==== Articles ====
 +  * [[http://​en.wikipedia.org/​wiki/​Atan2|Wikipedia:​Atan2]]
 +  * [[http://​en.wikipedia.org/​wiki/​Inverse_trigonometric_function|Wikipedia:​Inverse trigonometric function]]
QR Code
QR Code wiki:scripting_portal:lsl_functions:llatan2 (generated for current page)