Difference between revisions of "User:Pedro Oval/Uniform random rotation"
Jump to navigation
Jump to search
Pedro Oval (talk | contribs) m (Remove unnecessary local variables) |
Pedro Oval (talk | contribs) (Reuse r2 to prevent using another local) |
||
Line 6: | Line 6: | ||
// 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 | 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 - | float r1 = llSqrt(1.0 - r2); | ||
r2 = llSqrt(r2); | |||
return <r1*llSin(a1), r1*llCos(a1), r2*llSin(a2), r2*llCos(a2)>; | return <r1*llSin(a1), r1*llCos(a1), r2*llSin(a2), r2*llCos(a2)>; | ||
} | } | ||
</lsl> | </lsl> |
Revision as of 18:30, 26 August 2014
Based on a "graphics gem" by Ken Shoemake [1]
<lsl> 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)>;
} </lsl>