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:
Random distiribution of particles in a volume

Subject: Random distiribution of particles in a volume

From: Carlo Ventura

Date: 12 Jan, 2011 16:09:05

Message: 1 of 4

I need to put a random distribution of spherical particles into a cube, to choose the position of each particle I'd like to use matlab.Someone knows how to do that or which algorithm is needed?
Thanks!

Subject: Random distiribution of particles in a volume

From: Sean de

Date: 12 Jan, 2011 16:37:05

Message: 2 of 4

"Carlo Ventura" <cventura86@gmail.com> wrote in message <igkjn0$idi$1@fred.mathworks.com>...
> I need to put a random distribution of spherical particles into a cube, to choose the position of each particle I'd like to use matlab.Someone knows how to do that or which algorithm is needed?
> Thanks!

Pseudocode:
-generate n random integers between 1 and numel(volume) where n is the number of spheres you want
-generate n random numbers between 1 and the maximum sphere radius you want
-loop through and create them using the formula for a sphere. It can be found on the FAQ here:
http://matlab.wikia.com/wiki/FAQ#How_do_I_create_a_circle.3F

Good Luck!
-Sean

Subject: Random distiribution of particles in a volume

From: Timo

Date: 4 Mar, 2011 09:49:09

Message: 3 of 4

Hi Sean or Carlo,

I have a similar 'problem' but with some additional preconditions;

1. particles may not overlap
2. the part of the particle that falls off the edge of the cube has to be positioned at the oposite edge in such a way that connecting multiple of the same cubes would lead to a continuous distribution of particles.

I am looking for an efficient iteration procedure, hope you can help
-Timo

"Sean de " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <igklbh$3jg$1@fred.mathworks.com>...
> "Carlo Ventura" <cventura86@gmail.com> wrote in message <igkjn0$idi$1@fred.mathworks.com>...
> > I need to put a random distribution of spherical particles into a cube, to choose the position of each particle I'd like to use matlab.Someone knows how to do that or which algorithm is needed?
> > Thanks!
>
> Pseudocode:
> -generate n random integers between 1 and numel(volume) where n is the number of spheres you want
> -generate n random numbers between 1 and the maximum sphere radius you want
> -loop through and create them using the formula for a sphere. It can be found on the FAQ here:
> http://matlab.wikia.com/wiki/FAQ#How_do_I_create_a_circle.3F
>
> Good Luck!
> -Sean

Subject: Random distiribution of particles in a volume

From: Sean de

Date: 4 Mar, 2011 13:15:19

Message: 4 of 4

"Timo" wrote in message <ikqcik$t3e$1@fred.mathworks.com>...
> Hi Sean or Carlo,
>
> I have a similar 'problem' but with some additional preconditions;
>
> 1. particles may not overlap
> 2. the part of the particle that falls off the edge of the cube has to be positioned at the oposite edge in such a way that connecting multiple of the same cubes would lead to a continuous distribution of particles.
>
> I am looking for an efficient iteration procedure, hope you can help
> -Timo
>
> "Sean de " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <igklbh$3jg$1@fred.mathworks.com>...
> > "Carlo Ventura" <cventura86@gmail.com> wrote in message <igkjn0$idi$1@fred.mathworks.com>...
> > > I need to put a random distribution of spherical particles into a cube, to choose the position of each particle I'd like to use matlab.Someone knows how to do that or which algorithm is needed?
> > > Thanks!
> >
> > Pseudocode:
> > -generate n random integers between 1 and numel(volume) where n is the number of spheres you want
> > -generate n random numbers between 1 and the maximum sphere radius you want
> > -loop through and create them using the formula for a sphere. It can be found on the FAQ here:
> > http://matlab.wikia.com/wiki/FAQ#How_do_I_create_a_circle.3F
> >
> > Good Luck!
> > -Sean

Hi Timo,
I'm really busy today and won't be able to spend much time but here is route you could take, and we could hash out details next week if necessary:

-Generate n-random integers to be the centroids of your spheres.
-Generate n-random radii
-Begin populating your volume one sphere at a time with it's radii.
  -Apply constraint 1: If the new sphere's radius overlaps with another sphere 2 options:
      -If new sphere overlaps others reduce it.
      -Remove this centroid completely and generate a new one/try again.
  If you are looping through the centroids randomly, i.e. not starting at V(1,1,1) and traversing this will be truly random. If you're starting on one side/corner, that side will have bigger particles as the constraints encourage new spheres to be smaller.

Constraint 2 should be applied while you're creating the objects as well. If an object is on the edge, it can be determined easily (any(centroid - radius) < 1 OR any(centroid + radius >size(V)), where centroid is the [row col page] index of the centroid. You'll just need some fancy indexing tricks to place the sphere cap on the opposite side.

That will get you started; see how far you can get and post back with that.

Good Luck!
-Sean

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