Differences

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

Link to this comparison view

wiki:scripting_portal:lsl_functions:llanglebetween [2018/11/20 17:17]
Royale Mobian created
wiki:scripting_portal:lsl_functions:llanglebetween [2019/07/19 21:22] (current)
Royale Mobian
Line 1: Line 1:
 ====== llAngleBetween ====== ====== llAngleBetween ======
-===== Introduction =====+**[[wiki:​scripting_portal:​lsl_functions|Function]]:​ [[wiki:​scripting_portal:​lsl_types:​float|float]] llAngleBetween( [[wiki:​scripting_portal:​lsl_types:​rotation|rotation]] a, [[wiki:​scripting_portal:​lsl_types:​rotation|rotation]] b );** 
 +Returns a float that is the angle in radians between rotation **a** and rotation **b**. 
 +  * rotation a – start rotation  
 +  * rotation b – end rotation
  
 +===== Examples =====
 +<code ossl>
 +default
 +{
 +    touch_start(integer num_detected)
 +    {
 +        rotation currentRootRotation = llGetRootRotation();​
 +        float angle = llAngleBetween(ZERO_ROTATION,​ currentRootRotation);​
 + 
 +        // PUBLIC_CHANNEL has the integer value 0
 +        llSay(PUBLIC_CHANNEL,​
 +            "​llAngleBetween(ZERO_ROTATION,​ " + (string)currentRootRotation + ") = " + (string)angle);​
 +    }
 +}
 +</​code>​
  
-==== Example use cases: ​==== +===== See Also ===== 
- +==== Functions ​==== 
- +  * [[wiki:​scripting_portal:​lsl_functions:​llRotBetween|llRotBetween]]  
- +  * [[wiki:​scripting_portal:​lsl_functions:​llRot2Angle|llRot2Angle]] – Similar functionality used for the Axis-Angle format
-===== Examples ​=====+
  
 +===== Deep Notes =====
 +==== Reference ====
 <code ossl> <code ossl>
 +float AngleBetween(rotation a, rotation b)//simple but turns out to not be very accurate. 
 +
 +    return 2.0 * llAcos( llFabs(a.x * b.x + a.y * b.y + a.z * b.z + a.s * b.s) 
 +                      / llSqrt((a.x * a.x + a.y * a.y + a.z * a.z + a.s * a.s) 
 +                             * (b.x * b.x + b.y * b.y + b.z * b.z + b.s * b.s))); 
 +
 +</​code>​ 
 +<code ossl> 
 +float AngleBetween(rotation a, rotation b)//more complex implementation but more accurate, and reasonably fast. 
 +
 +    rotation r = b / a; // calculate the rotation between the two arguments as quaternion 
 +    float s2 = r.s * r.s; // square of the s-element 
 +    float v2 = r.x * r.x + r.y * r.y + r.z * r.z; // sum of the squares of the v-elements 
 +  
 +    if (s2 < v2) // compare the s-component to the v-component 
 +        return 2.0 * llAcos(llSqrt(s2 / (s2 + v2))); // use arccos if the v-component is dominant 
 +    if (v2) // make sure the v-component is non-zero 
 +        return 2.0 * llAsin(llSqrt(v2 / (s2 + v2))); // use arcsin if the s-component is dominant 
 +  
 +    return 0.0; // one or both arguments are scaled too small to be meaningful, or the values are the same, so return zero 
 +}//Written by Moon Metty @ Second Life & Miranda Umino @ Second Life. Minor optimizations by Strife Onizuka @ Second Life.
 </​code>​ </​code>​
QR Code
QR Code wiki:scripting_portal:lsl_functions:llanglebetween (generated for current page)