Difference between revisions of "LlRot2Angle"

From Second Life Wiki
Jump to navigation Jump to search
m (LSL llRot2Angle moved to LlRot2Angle: removing prefix)
m (<lsl> tag to <source>)
(11 intermediate revisions by 3 users not shown)
Line 3: Line 3:
|func=llRot2Angle|sort=Rot2Angle
|func=llRot2Angle|sort=Rot2Angle
|return_type=float|p1_type=rotation|p1_name=rot
|return_type=float|p1_type=rotation|p1_name=rot
|func_footnote=Use in conjunction with {{LSLG|llRot2Axis}}.<br/>To undo use {{LSLG|llAxisAngle2Rot}}.
|func_footnote=Use in conjunction with [[llRot2Axis]].<br/>To undo use [[llAxisAngle2Rot]].
|func_desc
|func_desc
|return_text=that is the rotation angle represented by '''rot'''
|return_text=that is the rotation angle represented by '''rot'''
|spec
|spec
|caveats
|caveats=This always returns a positive angle <= PI radians, that is, it is the unsigned minimum angle. A rotation of 3/2 PI radians (270 degrees) will return an angle of PI / 2 radians, not -PI / 2.
|constants
|constants
|examples
|examples
|helpers
|helpers
|also_functions=*{{LSLG|llRot2Left}}
|also_functions=
*{{LSLG|llRot2Fwd}}
{{LSL DefineRow||[[llAxisAngle2Rot]]}}
*{{LSLG|llRot2Up}}
{{LSL DefineRow||[[llRot2Axis]]}}
*{{LSLG|llRot2Axis}}
{{LSL DefineRow||[[llRot2Up]]}}
{{LSL DefineRow||[[llRot2Fwd]]}}
{{LSL DefineRow||[[llRot2Left]]}}
{{LSL DefineRow||[[llAngleBetween]]|Similar functionality.}}
|also_tests
|also_tests
|also_events
|also_events
|also_articles
|also_articles
|notes
|notes
|permission
|inventory
|negative_index
|cat1=Rotation
|cat1=Rotation
|cat2
|cat2
|cat3
|cat3
|cat4
|cat4
|deepnotes= ===Reference Implementation===
<table width=100><tr><td>
<source lang="lsl2">float Rot2Angle(rotation a)//simple but turns out to not be very accurate.
{
    return 2.0 * llAcos(llSqrt((a.s * a.s) / (a.x * a.x + a.y * a.y + a.z * a.z + a.s * a.s));
}</source>
<source lang="lsl2">float Rot2Angle(rotation r)//more complex implementation but more accurate, and reasonably fast.
{
    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; // argument is scaled too small to be meaningful, or it is a zero rotation, so return zero
}//Written by Moon Metty & Miranda Umino. Minor optimizations by Strife Onizuka</source>
</td></tr></table>
}}
}}

Revision as of 14:33, 22 January 2015

Summary

Function: float llRot2Angle( rotation rot );

Returns a float that is the rotation angle represented by rot

• rotation rot

Use in conjunction with llRot2Axis.
To undo use llAxisAngle2Rot.

Caveats

This always returns a positive angle <= PI radians, that is, it is the unsigned minimum angle. A rotation of 3/2 PI radians (270 degrees) will return an angle of PI / 2 radians, not -PI / 2.

All Issues ~ Search JIRA for related Bugs

Examples

See Also

Functions

•  llAxisAngle2Rot
•  llRot2Axis
•  llRot2Up
•  llRot2Fwd
•  llRot2Left
•  llAngleBetween Similar functionality.

Deep Notes

Reference Implementation

float Rot2Angle(rotation a)//simple but turns out to not be very accurate.
{ 
    return 2.0 * llAcos(llSqrt((a.s * a.s) / (a.x * a.x + a.y * a.y + a.z * a.z + a.s * a.s));
}
float Rot2Angle(rotation r)//more complex implementation but more accurate, and reasonably fast.
{
    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; // argument is scaled too small to be meaningful, or it is a zero rotation, so return zero
}//Written by Moon Metty & Miranda Umino. Minor optimizations by Strife Onizuka

Search JIRA for related Issues

Signature

function float llRot2Angle( rotation rot );