  | | | Random points on a unit sphere without biasing | Random points on a unit sphere without biasing 2005-06-14 - By Jerry Gamache
Back The gaussian distribution will reduce the number of points sitting in the corners of the cube, but culling triplets outside of the unit sphere would also do the same.
This is my take on Brad's script:
// SPHERICAL POINT DIST var radius = 0.5; var pnts = 1000;
// Create New particle Type var pTypeColl = CreateParticleType(); pType = pTypeColl(0);
// Create Cloud var cloud = ActiveSceneRoot.AddParticleCloud(); var cloudPrim = cloud.ActivePrimitive; cloudPrim.AddParticles(pnts, pType); particles = cloudPrim.Particles;
// For each particle, set a random distribution for(var i=0; i<pnts; i++){ // Get XSIMath objects setting pos var pos = XSIMath.CreateVector3(); // Calculate random quaternions var X = Math.random() * 2 - 1; var Y = Math.random() * 2 - 1; var Z = Math.random() * 2 - 1; // Used both for normalisation and rejection: r = Math.sqrt( X*X + Y*Y + Z*Z ) // If point is inside unit sphere, we can use it if ( r < 1.0 ) { // Normalize the vector using the already computed length pos.set(X/r,Y/r,Z/r); // Set particle to unit transform; particles(i).position = pos; } }
-- --Original Message-- -- From: owner-xsi@(protected) [mailto:owner-xsi@(protected)]On Behalf Of kim aldis Posted At: Tuesday, June 14, 2005 5:12 PM Posted To: xsi Conversation: Random points on a unit sphere without biasing Subject: RE: Random points on a unit sphere without biasing
True.
A Gaussian distribution would concentrate the generated points towards the centre so you'd have fewer outside the sphere. Not perfect but a deal better.
<trivia> Gaussian distribution just requires averaging a number of random numbers. The average of an infinite number of random numbers between lying between -1 and 1 is zero. I once knew a Cambridge graduate mathematician who couldn't get that. </trivia>
> -- --Original Message-- -- > From: owner-xsi@(protected) > [mailto:owner-xsi@(protected)] On Behalf Of Alan Jones > Sent: 14 June 2005 21:58 > To: XSI@(protected) > Subject: Re: Random points on a unit sphere without biasing > > X, Y, Z ones would be the same as doing a cube getting more > in the corners. Apparently gaussian is special... At least > that's what I assume from what I read on the mathworld page. > > Cheers, > > Alan. > > On 6/14/05, kim aldis <kim@(protected)> wrote: > > Why Gaussian? Wouldn't normalising x/y/z random numbers work? > > > > > > > > > -- --Original Message-- -- > > > From: owner-xsi@(protected) > > > [mailto:owner-xsi@(protected)] On Behalf Of Alan Jones > > > Sent: 14 June 2005 21:42 > > > To: XSI@(protected) > > > Subject: Re: Random points on a unit sphere without biasing > > > > > > Thanks Andy. After looking at the options I think I'm going to go > > > with the one at the bottom of the mathworld page. It suggested 3 > > > gaussian random numbers for X, Y and Z in a vector and > normalizing > > > the vector (at least that's what I think it said from my limited > > > math). I managed to track down an apparently fast way to generate > > > gaussian random numbers from evenly distributed ones so with any > > > luck I'm set. > > > > > > Thanks again, > > > > > > Alan. > > > > > > On 6/14/05, Andy Jones <andy@(protected)> wrote: > > > > The mathworld article answers this perfectly. Basically, > > > you pick one > > > > angle (theta) at random and a height (h) on the sphere at > > > random. You > > > > can check this by calculating the approximated surface > area (width > > > > * > > > > radius) of the bands around the sphere at different heights > > > along the > > > > sphere, and take the limit as dh -> 0. At the poles, the > > > width of the > > > > band is larger for a given height, and at the equator, the > > > radius of > > > > the band is obviously larger. In the limit, they have > a perfectly > > > > inverse relationship such that each band has the same > area. More > > > > generally, a good way to randomly sample vectors within a > > > given angle > > > > of an average vector is to restrict the height range to > > > [cos(angle), 1]. > > > > > > > > I think you can't pick points in a cube and normalize > > > because you'll > > > > bias more points at the corners and fewer points in the > > > middles of the > > > > faces, since a cube has more and less volume in those > > > directions. The > > > > same problem occurs if you sample on a cube's surface area. > > > The cube > > > > method is especially problematic because the biasing isn't > > > determined > > > > by the original vector direction. Of course, that > doesn't mean it > > > > doesn't work okay in practice for many applications. > > > > > > > > -Andy > > > > > > > > Alan Jones wrote: > > > > > > > > >Hi All, > > > > > > > > > >This is to the maths geniuses in the room. I want to > generate X > > > > >number of points on a unit sphere, but be sure I won't > have any > > > > >biasing involved. > > > > > > > > > >My first thought was just to use a couple of random numbers > > > > >(let's assume they don't have any bias) and then use > those with a > > > > >few sin and cos function etc to generate the points. Though I > > > > >have > > > a feeling > > > > >that would give me more points around the poles. > > > > > > > > > >Anyone have some good suggestions? > > > > > > > > > >Cheers, > > > > > > > > > >Alan. > > > > > > > > > >--- > > > > >Unsubscribe? Mail Majordomo@(protected) with the > > > following text in body: > > > > >unsubscribe xsi > > > > > > > > > > > > > > > > > > > > > > > --- > > > > Unsubscribe? Mail Majordomo@(protected) with the > > > following text in body: > > > > unsubscribe xsi > > > > > > > > > > --- > > > Unsubscribe? Mail Majordomo@(protected) with the > following text in > > > body: > > > unsubscribe xsi > > > > > > > > > > --- > > Unsubscribe? Mail Majordomo@(protected) with the > following text in body: > > unsubscribe xsi > > > > --- > Unsubscribe? Mail Majordomo@(protected) with the following > text in body: > unsubscribe xsi > >
--- Unsubscribe? Mail Majordomo@(protected) with the following text in body: unsubscribe xsi
--- Unsubscribe? Mail Majordomo@(protected) with the following text in body: unsubscribe xsi
|
|
 |