Path: news.mathworks.com!not-for-mail
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$1@fred.mathworks.com>
References: <ias74s$i04$1@fred.mathworks.com>
Reply-To: "Bruno Luong" <b.luong@fogale.findmycountry>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1288810324 923 172.30.248.37 (3 Nov 2010 18:52:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 3 Nov 2010 18:52:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 390839
Xref: news.mathworks.com comp.soft-sys.matlab:683633

"Christian Schultz" <spamcatcher@remove.this.easy.com> wrote in message <ias74s$i04$1@fred.mathworks.com>...
> 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]
r1=1;
r2=2;
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