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$>
References: <>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: 1233427741 1914 (31 Jan 2009 18:49:01 GMT)
NNTP-Posting-Date: Sat, 31 Jan 2009 18:49:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: comp.soft-sys.matlab:515167

gregthom <> wrote in message <>...
> ......
> 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