Why does my gravity simulation always rotate the same way?

Join the discussion
Registration is free. Start your own thread to ask a follow-up.
6 replies · 3K views
funkpun
Messages
3
Reaction score
0
Hi all. I've been playing around with a simple gravity simulator I wrote in Processing. I have a version that impliments a second degree modified Euler integration scheme on particles in three dimensions. Attached is a screen strip of screen captures showing the first few moments of the simulation.

What I find interesting/weird is that the direction of rotation as the sheet collapses is always the same -- the top falls forward, the bottom falls back (particles become more and more cyan as they move forward).

I don't believe this is a programming issue, as the documentation for the randomize function says: "Each time the random() function is called, it returns an unexpected value within the specified range..."

I'm curious if there might be a physics or numerical reason for this tendency.

I'm happy to share my code, if you want to see it -- although it's still extremely messy and gnarly and such.

Cheers,
Fp.
 

Attachments

  • strip.jpg
    strip.jpg
    5.4 KB · Views: 447
Physics news on Phys.org
If you seed the random number generator with the same seed each time then it will give exactly the same results each time. Try seeding with a different number.
 
"If you seed the random number generator with the same seed each time then it will give exactly the same results each time. Try seeding with a different number."

I'm *not* using a seed. It's randomizing properly.

Fp
 
All random number generators use a seed. If you are not explicitly setting it then it is probably using the same default seed each time resulting in the exact same simulation each time.

Set the seed explicitly and then change it and see what happens.
 
It's not the random seed -- randomize is working correcly. There's also no bias in the way the sheet is constructed:

for (int i = 0; i <= bodies.length-1; i++) {
bodies = new Objects(random(w), random(h),random(0, 50), random(0,200));
}

create a particle w. random x,y and z between 0 and 50, with mass of 0 to 200.

Fp