Is this possible to do in Processing? (sphere packing)

edited November 2016 in How To...

Hi. I'm a new person and just wanted to ask a question about the ability of Processing to handle a certain 3D simulation problem. The system I'd like to model is:

  1. Start with flexible three-dimensional sphere (sphere 0).

  2. This sphere has the property that it forms a layer (layer 1) of non-overlapping flexible spheres to cover its surface. These spheres are of the same size as sphere 0. You can fit 12 non-overlapping spheres around a central sphere of the same size, but there's not quite enough room to fit a 13th sphere. So, at this point, the 13th sphere will be fit in, it and its immediate neighbors will be compressed against each other.

  3. After the layer 1 spheres form, two things happen:

    A. Because the compressed spheres are trying to assume their natural spherical shape, the 13th sphere and its neighbors will push out against each other and cause these spheres to move away from each other and as they move interact with other spheres.

    B. The surfaces of the layer 1 spheres that aren't already covered by other spheres will then cause a new layer (layer 2) of non-overlapping flexible spheres to cover those surfaces. This process continues ad infinitum forming ever more layers of flexible spheres. Any compressed spheres in layer 2 and in the succeeding layers will also push out against each other and cause the spheres to move away.

  4. As the spheres from step 3A move away from each other, their surfaces become uncovered. As soon as this happens, those surfaces of the moving spheres create new flexible spheres to cover their surfaces.

  5. Steps 3 and 4 continue ad infinitum.

    I'd like to simulate this process and see how the spheres move and interact. I've been trying to learn Houdini to model this but I'm not sure if it will be able to handle this problem. Can the Processing language handle this simulation? Or, would sticking with Houdini be better? Approximately how long might it take for a novice to learn Processing to make this simulation? I've got a small amount of experience with Houdini and Python. Is it possible to hire people to make custom simulations like this one?

    Any advice you might be able to provide would be greatly appreciated. Thank you in advance! Roger

Tagged:

Answers

  • Answer ✓

    Here I have some pictures when creating a sphere0 and 6 sphere1 type. To fit 12, I will need to go through the mathematics to calculate the normal vector at each surface of the 12 faced shape.

    However, to simulate the behavior of the 13th sphere requires a bit more of work. If you want to see the interaction between spheres, you will need to simulate it and work through all the mathematics. As I understand, when you add the 13th sphere, one sphere will be pop-out into layer 2.

    What do you mean with non-overlapping flexible spheres? I am guessing they don't deform but they move?

    Kf

    final int radius=50;
    final int diameter=2*radius;
    
    void setup() {
      size(600, 600, P3D);
      noStroke();
    }
    
    void draw() {
      background(0);
      translate(width>>1, height>>1, 30);
    
      fill(250, 50, 64);
      text("Sphere0", width*0.2, -height*0.40);
      fill(250, 140, 50);
      text("Sphere1-positive", width*0.2, -height*0.35);
      fill(250, 250, 50);
      text("Sphere1-negative", width*0.2, -height*0.30);
    
      lights();
      rotateY(map(mouseX, 0, width, -PI, PI));
      rotateX(map(mouseY, 0, height, -PI, PI));
    
      fill(250, 140, 50);
    
      pushMatrix();
      translate(diameter, 0, 0);
      sphere(radius);
      popMatrix();
    
      pushMatrix();
      translate(0, diameter, 0);
      sphere(radius);
      popMatrix();
    
      pushMatrix();
      translate(0, 0, diameter);
      sphere(radius);
      popMatrix();
    
      fill(250, 250, 50);
    
      pushMatrix();
      translate(-diameter, 0, 0);
      sphere(radius);
      popMatrix();
    
      pushMatrix();
      translate(0, -diameter, 0);
      sphere(radius);
      popMatrix();
    
      pushMatrix();
      translate(0, 0, -diameter);
      sphere(radius);
      popMatrix();
    
      fill(250, 50, 64);
      sphere(radius);
    }
    

    view-0257 view-0982 view-1176 ![view-1338]

  • @Roger -- Processing doesn't have any particular affordances for the kind of "compressed sphere" physics modeling that you are talking about. Its primitives are graphical primitives -- sphere, box, mesh, etc. -- and not physics model primitives. Models of compression and flow will have to be calculated in Java using an object model and then expressed as graphics after the fact. Even then, there aren't squishy 3D primitives, so there may be a fair amount of work on the graphics end.

    That said, it isn't necessarily harder than in Python -- Processing just doesn't have anything built-in that I can think of to make it easier.

    As to whether forum-goers with physics simulation expertise might be for-hire, I'll let them respond....

  • kfrajer: Thank you! I didn't mean for you to do all that work, but thank you. By non-overlapping flexible spheres, I do mean flexible, or softbody/squishy, kind of like water balloons. I'd like them all to be non-overlapping in that their borders don't overlap. I had trouble avoiding the non-overlapping part when I was using another thing called Blender. Because they're all non-overlapping and softbody, they'll bulge out against each other and will kind of explode away from each other. This sounds easier said than done, unfortunately.

    Jeremy: Thank you, too! That's very useful to know that the physics and compression stuff isn't built into Processing and would have to be calculated outside and brought in. One nice thing about Houdini is that the physics stuff is built in. But, as a relative newcomer and a non-programmer, learning both Houdini and the Python required for more fine level control of Houdini is hard for me, and I'm wondering if what I want to model might be beyond me. But, I'll keep at it, I guess.

    Thanks to both of you.  I really appreciate it, and you both answered my question!
    

    Roger

  • Good luck with the project, @Roger.

    As it turns out, while it is true that the Processing core doesn't have softbody physics support, there appears to be extensive softbody physics support built into the PixelFlow library.

    Check out PixelFlow and the PixelFlow JavaDoc Reference -- in particular the package:

    and the class:

  • Answer ✓

    @jeremydouglass Very impressive library.

    @Roger After you install the library, check the example SoftBody2D_Playground.pde. It might show some effects that are relevant to your simulation.

    I have to ask. After the spheres in level 1 begin populating level2, what stop them from moving around into other positions in level2? Adhesive forces? Friction?

    Kf

  • Answer ✓

    Box2D library might also contain an example relevant to your task. Check the example that comes with the library: Blobby.pde

    Kf

  • edited November 2016

    Jeremy and Kfrajer,

    Thanks for the link to the libraries!  I'll check them out.  
    
    In  regard to the spheres in level 1 and 2, I think all the spheres in all the
    

    layers will start moving around and bouncing into and interacting with each other. Nothing other than these collisions should stop them. And, as they move, their surfaces will become uncovered and new spheres will be formed to cover the uncovered areas. What I'm thinking of is kind of like an explosion caused by the compression of the spheres and as the spheres explode out, more spheres will be added to cover the uncovered surfaces. This will sound kind of stupid, but I'm trying to model some ideas of mine about the Big Bang. The spheres would be the units that make up the universe, the compression and bulging out as they're all squeezed in is what energy is and what causes the bang, and as the new spheres are formed, this is like expanding space. I'm just an amateur, and this is probably all wrong, but I've found that without any evidence, no one will ever even listen to these ideas. So, I'm trying to model them to see if anything resembling actual physics shows up. In the worst case, it's a hobby that keeps me busy. But, that might have been more information than you wanted to know! :-)

    Now that I know about these softbody physics libraries, maybe Processing might
    

    be an alternative to Houdini. Thanks to both you guys! You were a lot more helpful than the people at the Houdini and Blender help forums.

    Roger

    If you're really bored, the model I'm thinking of is at:

    https://sites.google.com/site/ralphthewebsite/filecabinet/why-is-there-something-rather-than-nothing

    in the section labeled Use of the Proposed Solution to Build a Model...

Sign In or Register to comment.