From: "Bruno Luong" <b.luong@fogale.findmycountry>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Creating a spherical mass distribution
Date: Wed, 3 Nov 2010 18:52:04 +0000 (UTC)
Organization: FOGALE nanotech
Lines: 15
Message-ID: <iasb0k$sr$>
References: <ias74s$i04$>
Reply-To: "Bruno Luong" <b.luong@fogale.findmycountry>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1288810324 923 (3 Nov 2010 18:52:04 GMT)
NNTP-Posting-Date: Wed, 3 Nov 2010 18:52:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 390839
Xref: comp.soft-sys.matlab:683633

"Christian Schultz" <> wrote in message <ias74s$i04$>...
> I'm doing this simulation on a spherical cloud of gas with a 1/r density profile. Of course in order to do any simulations in the first place I need some sample particles distributed on a spherical lattice in a symmetric, uniform way. How do you make a discrete, spherical symmetric cloud in Matlab? If I just needed a spherical surface I could just approximate the spherical surface with a regular polygon, but I need one more dimension since the cloud is a ball. 

% Generate a n 3D random points with 1/r distribution within the radius
% interval [r1,r2]
n = 10000;

s = randn(3,n); 
r = sqrt(rand(1,n)*(r2^2-r1^2)+r1^2);
c = r./sqrt(sum(s.^2,1));
s = bsxfun(@times, s, c);

% Bruno