Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: 3D sphere creation
Date: Sat, 31 Jan 2009 18:49:01 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 20
Message-ID: <gm26et$1rq$1@fred.mathworks.com>
References: <1c9522f5-4f3a-477c-bf96-a919a0aaecf4@g3g2000pre.googlegroups.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1233427741 1914 172.30.248.38 (31 Jan 2009 18:49:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 31 Jan 2009 18:49:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:515167

gregthom <gregthom99@yahoo.com> wrote in message <1c9522f5-4f3a-477c-bf96-a919a0aaecf4@g3g2000pre.googlegroups.com>...
> ......
> and then my volume is vol = zeros(100,100,100);
> and the xyz spatial info for my volume is
> X = linspace(-20,20,100);Z = linspace(-20,20,100);,Z = linspace
> (-20,20,100);
> 
> How can I set the positions occupied by points x,y,z (points in
> sphere) in my vol matrix to = 1; and 0 other wise. If I do that then I
> have a sphere in my 3D volume . Anyone else perhaps with a simpler way
> of doing this ?
> ......

  In the question you have posed, Greg, your x, y, z arrays are of no help.  To lie inside a sphere, or more generally inside some kind of spherical sector, you need expressions for r, theta, and phi as functions of x, y, and z so that the appropriate inequalities can be tested.  Of course in your particular example, all you need is r <= 30, so your test is simply

 [x2,y2,z2] = meshgrid(X,Y,Z);
 r = sqrt(x2.^2+y2.^2+z2.^2);
 vol(r<=30) = 1;

Roger Stafford