The code performs the follows the reasoning: for a chosen , and , select a random with , with and with . If and only if the equation of the ellipsoid in standard form:
is satisfied, then the generated and values describe a point which lies within the elipsoid's perimeter. Otherwise, select new values for , and and loop until the equation is satisfied.
Since we want, in this case, an upper elipsoid, all values must be positive.
/////////////////////////////////////////////////////////////////////////// // Copyright (C) 2016 Wizardry and Steamworks - License: GNU GPLv3 // /////////////////////////////////////////////////////////////////////////// vector wasUpperEllipsoid(float a, float b, float c) { float x = llPow(-1, 1 + (integer) llFrand(2)) * llFrand(a); float y = llPow(-1, 1 + (integer) llFrand(2)) * llFrand(b); float z = llFrand(c); if(llPow(x/a,2) + llPow(y/b,2) + llPow(z/c,2) <= 1) return <x, y, 0>; return wasUpperEllipsoid(a, b, c); }