Difference between revisions of "User:Pedro Oval/Uniform random rotation"

From Second Life Wiki
Jump to navigation Jump to search
(Added Uniform random rotation)
 
m (<lsl> to <source>)
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
Based on a "graphics gem" by Ken Shoemake [http://www.google.com/search?hl=en&q=%22graphics+gems+iii%22+%22compute+two+uniformly+distributed+angles%22&btnI=1]
Based on a "graphics gem" by Ken Shoemake [http://books.google.com/books?id=xmW_u3mQLmQC&pg=PA130]


<lsl>
<source lang="lsl2">
rotation UniformRandRot()
rotation UniformRandRot()
{
{
     // Method from Graphic Gems 3, "Uniform Random Rotations"
     // Method from Graphic Gems 3, "Uniform Random Rotations"
     // by Ken Shoemake, p.130
     // by Ken Shoemake, p.130
     float x0 = llFrand(1.0);
     float r2 = llFrand(1.0);
     float a1 = llFrand(TWO_PI);
     float a1 = llFrand(TWO_PI);
     float a2 = llFrand(TWO_PI);
     float a2 = llFrand(TWO_PI);
     float r1 = llSqrt(1.0 - x0);
     float r1 = llSqrt(1.0 - r2);
     float r2 = llSqrt(x0);
     r2 = llSqrt(r2);
     float s1 = llSin(a1);
     return <r1*llSin(a1), r1*llCos(a1), r2*llSin(a2), r2*llCos(a2)>;
    float c1 = llCos(a1);
    float s2 = llSin(a2);
    float c2 = llCos(a2);
    return <s1*r1, c1*r1, s2*r2, c2*r2>;
}
}
</lsl>
</source>

Latest revision as of 21:35, 23 January 2015

Based on a "graphics gem" by Ken Shoemake [1]

rotation UniformRandRot()
{
    // Method from Graphic Gems 3, "Uniform Random Rotations"
    // by Ken Shoemake, p.130
    float r2 = llFrand(1.0);
    float a1 = llFrand(TWO_PI);
    float a2 = llFrand(TWO_PI);
    float r1 = llSqrt(1.0 - r2);
    r2 = llSqrt(r2);
    return <r1*llSin(a1), r1*llCos(a1), r2*llSin(a2), r2*llCos(a2)>;
}