Path: news.mathworks.com!not-for-mail From: <HIDDEN> Newsgroups: comp.soft-sys.matlab Subject: Re: Creating a spherical mass distribution Date: Sun, 7 Nov 2010 15:34:04 +0000 (UTC) Organization: The MathWorks, Inc. Lines: 37 Message-ID: <ib6gtc$693$1@fred.mathworks.com> References: <ias74s$i04$1@fred.mathworks.com> <iasb0k$sr$1@fred.mathworks.com> <iasmg3$3ng$1@fred.mathworks.com> <iatiao$73b$1@fred.mathworks.com> Reply-To: <HIDDEN> NNTP-Posting-Host: webapp-05-blr.mathworks.com Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: fred.mathworks.com 1289144044 6435 172.30.248.35 (7 Nov 2010 15:34:04 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Sun, 7 Nov 2010 15:34:04 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 2595159 Xref: news.mathworks.com comp.soft-sys.matlab:684485 "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <iatiao$73b$1@fred.mathworks.com>... > > > > > I tried your code, but it produces random numbers on a straight line (in 3-space), and not a spherical distribution. > > It's odd, here is the result I get with 10 points > > >> r1=1; > r2=2; > n = 10; > > 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); > >> s > > s = > > -0.9060 -0.1235 1.1516 0.7192 0.1040 -0.6584 -0.5701 -1.0032 1.3177 0.7311 > 0.7269 -0.6609 -0.8484 -0.4345 1.7098 -0.0874 0.3903 -0.7442 -0.6219 0.0003 > -0.8134 -0.8583 -0.0607 1.5519 0.0895 -0.9945 -0.7686 0.0756 -0.6188 -1.0419 > > Then when I do that > > plot3(s(1,:),s(2,:),s(3,:),'.') > > There definitively not in the straight line. > > Bruno I don't know what went wrong, when I run it on my Ubuntu laptop it works just fine. Thank you I figured out a way to do what I wanted. I guess I could have been a bit more specific in my description of the problem. I just made a regular uniform rectangular grid, and confined it to a sphere by discarding the part of the grid that was outside. Then I simply did a radial stretch of the grid by sending r_old into r_new=|r_old|r_old. That seems to do the trick. Than you all for your contributions.