Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Generate a sphere in a 3d matrix

Subject: Generate a sphere in a 3d matrix

From: Jacky

Date: 24 May, 2011 23:02:05

Message: 1 of 6

Dear All,

I am trying to generate sphere in a 100-by-100-by-100 matrix (or 3D matrix).
I have been referring to the following thread which is similar to my case but i guess it is different than what i am looking-
http://www.mathworks.com/matlabcentral/newsreader/view_thread/297108

Please help me how to generate a sphere in a N-by-N-by-N matrix.
Best
Jacky

Subject: Generate a sphere in a 3d matrix

From: Roger Stafford

Date: 25 May, 2011 03:18:03

Message: 2 of 6

"Jacky" wrote in message <irhddc$7fc$1@newscl01ah.mathworks.com>...
> Dear All,
>
> I am trying to generate sphere in a 100-by-100-by-100 matrix (or 3D matrix).
> I have been referring to the following thread which is similar to my case but i guess it is different than what i am looking-
> http://www.mathworks.com/matlabcentral/newsreader/view_thread/297108
>
> Please help me how to generate a sphere in a N-by-N-by-N matrix.
> Best
> Jacky
- - - - - - - - - -
  Two questions:

1. What is your understanding of a 'sphere' in this context? Is it a 2D surface of points all equidistant from its center, or is it all points on and inside such a surface? Your wish for a three-dimensional array would seem to indicate that you are interested in the solid interior of a sphere.

2. What content do you wish your single 3D array to have? Are the elements to be 'true' or 1 inside the sphere and 'false' or 0 outside?

Roger Stafford

Subject: Generate a sphere in a 3d matrix

From: Ahmed

Date: 26 May, 2014 18:02:08

Message: 3 of 6

Hi,

I am facing the same problem. I am trying to generate a sphere in a 3D matrix. Something like the phantom function in matlab, but with a single sphere at the origin and in 3D instead of 2D.

Thanks,
Ahmed Elkady

"Roger Stafford" wrote in message <irhsdb$dfs$1@newscl01ah.mathworks.com>...
> "Jacky" wrote in message <irhddc$7fc$1@newscl01ah.mathworks.com>...
> > Dear All,
> >
> > I am trying to generate sphere in a 100-by-100-by-100 matrix (or 3D matrix).
> > I have been referring to the following thread which is similar to my case but i guess it is different than what i am looking-
> > http://www.mathworks.com/matlabcentral/newsreader/view_thread/297108
> >
> > Please help me how to generate a sphere in a N-by-N-by-N matrix.
> > Best
> > Jacky
> - - - - - - - - - -
> Two questions:
>
> 1. What is your understanding of a 'sphere' in this context? Is it a 2D surface of points all equidistant from its center, or is it all points on and inside such a surface? Your wish for a three-dimensional array would seem to indicate that you are interested in the solid interior of a sphere.
>
> 2. What content do you wish your single 3D array to have? Are the elements to be 'true' or 1 inside the sphere and 'false' or 0 outside?
>
> Roger Stafford

Subject: Generate a sphere in a 3d matrix

From: Steven Lord

Date: 27 May, 2014 01:36:15

Message: 4 of 6


"Ahmed " <ahmed.elkady@gmail.com> wrote in message
news:llvvj0$cic$1@newscl01ah.mathworks.com...
> Hi,
>
> I am facing the same problem. I am trying to generate a sphere in a 3D
> matrix. Something like the phantom function in matlab, but with a single
> sphere at the origin and in 3D instead of 2D.

What are YOUR answers to Roger's two questions?

> "Roger Stafford" wrote in message
> <irhsdb$dfs$1@newscl01ah.mathworks.com>...

*snip*

>> Two questions:
>>
>> 1. What is your understanding of a 'sphere' in this context? Is it a 2D
>> surface of points all equidistant from its center, or is it all points on
>> and inside such a surface? Your wish for a three-dimensional array would
>> seem to indicate that you are interested in the solid interior of a
>> sphere.
>>
>> 2. What content do you wish your single 3D array to have? Are the
>> elements to be 'true' or 1 inside the sphere and 'false' or 0 outside?

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Generate a sphere in a 3d matrix

From: Ahmed

Date: 27 May, 2014 16:39:13

Message: 5 of 6

Hi Steve,

Thanks for your prompt reply. The sphere I would like to generate has values of 1s inside, and the rest of the matrix is zero-filled. I have code for processing 3D MRI data, and I wish to use this spherical phantom to test my code.

Thanks.


"Steven Lord" <Steven_Lord@mathworks.com> wrote in message <lm0q6j$bn3$1@newscl01ah.mathworks.com>...
>
> "Ahmed " <ahmed.elkady@gmail.com> wrote in message
> news:llvvj0$cic$1@newscl01ah.mathworks.com...
> > Hi,
> >
> > I am facing the same problem. I am trying to generate a sphere in a 3D
> > matrix. Something like the phantom function in matlab, but with a single
> > sphere at the origin and in 3D instead of 2D.
>
> What are YOUR answers to Roger's two questions?
>
> > "Roger Stafford" wrote in message
> > <irhsdb$dfs$1@newscl01ah.mathworks.com>...
>
> *snip*
>
> >> Two questions:
> >>
> >> 1. What is your understanding of a 'sphere' in this context? Is it a 2D
> >> surface of points all equidistant from its center, or is it all points on
> >> and inside such a surface? Your wish for a three-dimensional array would
> >> seem to indicate that you are interested in the solid interior of a
> >> sphere.
> >>
> >> 2. What content do you wish your single 3D array to have? Are the
> >> elements to be 'true' or 1 inside the sphere and 'false' or 0 outside?
>
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com

Subject: Generate a sphere in a 3d matrix

From: Steven Lord

Date: 27 May, 2014 16:53:20

Message: 6 of 6


"Ahmed " <ahmed.elkady@gmail.com> wrote in message
news:lm2f3h$k95$1@newscl01ah.mathworks.com...
> Hi Steve,
>
> Thanks for your prompt reply. The sphere I would like to generate has
> values of 1s inside, and the rest of the matrix is zero-filled. I have
> code for processing 3D MRI data, and I wish to use this spherical phantom
> to test my code.

In that case, use MESHGRID or NDGRID to generate a 3-D array of coordinates,
then compute the distance from each point (represented by corresponding
elements from each of the three 3-D arrays) to the origin (or center of your
circle) and compare it to the radius of the desired sphere.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us