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:
3d sphere inside matix

Subject: 3d sphere inside matix

From: Aimen

Date: 24 Nov, 2010 16:05:03

Message: 1 of 6

I need a 3d sphere of 1's in a cubic matrix of zeros. I cannot thing of how to do this

Regards

Subject: 3d sphere inside matix

From: Sean de

Date: 24 Nov, 2010 17:25:05

Message: 2 of 6

"Aimen " <ams107@ic.ac.uk> wrote in message <icjd3e$qi6$1@fred.mathworks.com>...
> I need a 3d sphere of 1's in a cubic matrix of zeros. I cannot thing of how to do this
>
> Regards

Use the formula for a sphere:
%Sphere of 1s with radius 25 centered at 50,50,50 in a 100x100x100 zero matrix
%%%
%Engine
[xx yy zz] = meshgrid(1:100,1:100,1:100);
S = sqrt((xx-50).^2+(yy-50).^2+(zz-50).^2)<=25;

%Visualize
isosurface(S,0)
%SCd
%%%

Subject: 3d sphere inside matix

From: Aimen

Date: 25 Nov, 2010 12:28:05

Message: 3 of 6

"Sean de " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <icjhph$6id$1@fred.mathworks.com>...
> "Aimen " <ams107@ic.ac.uk> wrote in message <icjd3e$qi6$1@fred.mathworks.com>...
> > I need a 3d sphere of 1's in a cubic matrix of zeros. I cannot thing of how to do this
> >
> > Regards
>
> Use the formula for a sphere:
> %Sphere of 1s with radius 25 centered at 50,50,50 in a 100x100x100 zero matrix
> %%%
> %Engine
> [xx yy zz] = meshgrid(1:100,1:100,1:100);
> S = sqrt((xx-50).^2+(yy-50).^2+(zz-50).^2)<=25;
>
> %Visualize
> isosurface(S,0)
> %SCd
> %%%
Thank you for your help. However maybe i was not clear enough. i need to make a matrix of zero's with a sphere of 1's in the matrix.
i have started with a matrix of zero's by using:
A = zeros(L,L,L)
I will set radius of sphere. My biggest problem is that i am unable to use the vector equation you have sent as i cannot set an x, y and z axes in my 3d matrix of zero's. i need to use element positions i think to achieve this but dont know how

Subject: 3d sphere inside matix

From: Sean de

Date: 30 Nov, 2010 21:34:05

Message: 4 of 6

"Aimen " <ams107@ic.ac.uk> wrote in message <iclkol$mc9$1@fred.mathworks.com>...
> "Sean de " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <icjhph$6id$1@fred.mathworks.com>...
> > "Aimen " <ams107@ic.ac.uk> wrote in message <icjd3e$qi6$1@fred.mathworks.com>...
> > > I need a 3d sphere of 1's in a cubic matrix of zeros. I cannot thing of how to do this
> > >
> > > Regards
> >
> > Use the formula for a sphere:
> > %Sphere of 1s with radius 25 centered at 50,50,50 in a 100x100x100 zero matrix
> > %%%
> > %Engine
> > [xx yy zz] = meshgrid(1:100,1:100,1:100);
> > S = sqrt((xx-50).^2+(yy-50).^2+(zz-50).^2)<=25;
> >
> > %Visualize
> > isosurface(S,0)
> > %SCd
> > %%%
> Thank you for your help. However maybe i was not clear enough. i need to make a matrix of zero's with a sphere of 1's in the matrix.
> i have started with a matrix of zero's by using:
> A = zeros(L,L,L)
> I will set radius of sphere. My biggest problem is that i am unable to use the vector equation you have sent as i cannot set an x, y and z axes in my 3d matrix of zero's. i need to use element positions i think to achieve this but dont know how


What I gave you does EXACTLY what you have requested.
If you look at S, you'll see that it is a 3d matrix, if you look at any slice where a sphere with radius 25 centered at (50, 50, 50) would be, you'll see the corresponding ones with everything else left as zeros.

Subject: 3d sphere inside matix

From: Aimen

Date: 1 Dec, 2010 15:30:35

Message: 5 of 6

"Sean de " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <id3qkd$uo$1@fred.mathworks.com>...
> "Aimen " <ams107@ic.ac.uk> wrote in message <iclkol$mc9$1@fred.mathworks.com>...
> > "Sean de " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <icjhph$6id$1@fred.mathworks.com>...
> > > "Aimen " <ams107@ic.ac.uk> wrote in message <icjd3e$qi6$1@fred.mathworks.com>...
> > > > I need a 3d sphere of 1's in a cubic matrix of zeros. I cannot thing of how to do this
> > > >
> > > > Regards
> > >
> > > Use the formula for a sphere:
> > > %Sphere of 1s with radius 25 centered at 50,50,50 in a 100x100x100 zero matrix
> > > %%%
> > > %Engine
> > > [xx yy zz] = meshgrid(1:100,1:100,1:100);
> > > S = sqrt((xx-50).^2+(yy-50).^2+(zz-50).^2)<=25;
> > >
> > > %Visualize
> > > isosurface(S,0)
> > > %SCd
> > > %%%
> > Thank you for your help. However maybe i was not clear enough. i need to make a matrix of zero's with a sphere of 1's in the matrix.
> > i have started with a matrix of zero's by using:
> > A = zeros(L,L,L)
> > I will set radius of sphere. My biggest problem is that i am unable to use the vector equation you have sent as i cannot set an x, y and z axes in my 3d matrix of zero's. i need to use element positions i think to achieve this but dont know how
>
>
> What I gave you does EXACTLY what you have requested.
> If you look at S, you'll see that it is a 3d matrix, if you look at any slice where a sphere with radius 25 centered at (50, 50, 50) would be, you'll see the corresponding ones with everything else left as zeros.

Yes, you did. I apologise. When i wrote the message i was struggelling with meshgrid function. i realise now that it numbers locates the elements in a matrix in 3d space. thank you very much for your help and i apologise for not realising.

a minor question, if i wanted to set boundary conditions for the box, could i do this is a program file (.m file) or wwuld i need to create a model??

Subject: 3d sphere inside matix

From: Aimen

Date: 6 Jan, 2011 12:55:08

Message: 6 of 6

"Sean de " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <id3qkd$uo$1@fred.mathworks.com>...
> "Aimen " <ams107@ic.ac.uk> wrote in message <iclkol$mc9$1@fred.mathworks.com>...
> > "Sean de " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <icjhph$6id$1@fred.mathworks.com>...
> > > "Aimen " <ams107@ic.ac.uk> wrote in message <icjd3e$qi6$1@fred.mathworks.com>...
> > > > I need a 3d sphere of 1's in a cubic matrix of zeros. I cannot thing of how to do this
> > > >
> > > > Regards
> > >
> > > Use the formula for a sphere:
> > > %Sphere of 1s with radius 25 centered at 50,50,50 in a 100x100x100 zero matrix
> > > %%%
> > > %Engine
> > > [xx yy zz] = meshgrid(1:100,1:100,1:100);
> > > S = sqrt((xx-50).^2+(yy-50).^2+(zz-50).^2)<=25;
> > >
I am trying to use this model to simulate steady state heat conduction in the cube. However I am having difficulty with the 'S' matrix you created. The condition used means that I can only have obes and zero's in the matrix I believe. Could you possibly clarify how I could get around that please.

Regards
Aimen
> > > %Visualize
> > > isosurface(S,0)
> > > %SCd
> > > %%%
> > Thank you for your help. However maybe i was not clear enough. i need to make a matrix of zero's with a sphere of 1's in the matrix.
> > i have started with a matrix of zero's by using:
> > A = zeros(L,L,L)
> > I will set radius of sphere. My biggest problem is that i am unable to use the vector equation you have sent as i cannot set an x, y and z axes in my 3d matrix of zero's. i need to use element positions i think to achieve this but dont know how
>
>
> What I gave you does EXACTLY what you have requested.
> If you look at S, you'll see that it is a 3d matrix, if you look at any slice where a sphere with radius 25 centered at (50, 50, 50) would be, you'll see the corresponding ones with everything else left as zeros.

Tags for 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