Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Simulation Programming: Spawning particles at random position

  1. May 10, 2012 #1
    Hi, I am making a program with the simulation software Breve. It codes in Python or in Steve (their own language). In my simulation, spherical particle with random radius are being spawned at random position into a little zone. My problem is that those particle cannot be superposed. I don't know how to program it in such a way that the particle will spawn at a position where they will touch no other particle.


    Thanks
    PytLove
     
  2. jcsd
  3. May 10, 2012 #2
    Simple brute force method:

    For each new particle check to see the distance between the center of the particle and the center of each previous particle is greater than the sum of the radius of each of those two particles. If it isn't then throw the new one away and generate another particle.
     
  4. May 10, 2012 #3
    Thank you that seems to work well. Unfortunately that takes a long time with a lot of sphere and sometimes the program crash because the loop verifying the sphere position run for too much time. I would like to at first take a random position, and if it touches another sphere choose a position where there is nothing. In that way one sphere could not be spawned more than two times. I don't know if it's possible but I think that could make my program faster.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Simulation Programming: Spawning particles at random position
Loading...