I agree with one of the YouTube commenters: you accidentally made a form of machine learning, it's essentially a physical problem solving algorithm. With no change in velocity possible, each collision adjusts the position of a ball away from the one it collided with, and the entire system naturally seeks out a solution where no collisions occur.
Except that here in the real world, things having the same orbital period pretty much isn't a thing, and orbits are perturbed by anything and everything. This "simulation" doesn't consider all the factors that make stuff hard.
I guess if you would want to program this, you would first create N random paths, and then increase the sizes of the bubbles iteratively (you can increase a bubble's size to the maximum size it could be by checking it's minimal distance to every other bubble, and then subtract the other bubble's size)
No, I think the best way would be to do exactly this, only intentionally. Just start with random paths and sizes and then simulate the collisions until reaching a steady state.
You mean you would make the collision in the beginning artificial and then with every collision you would artificially correct their path to the beforehand calculated one?
Now you let them orbit around the gravity center with random start positions/velocities (simulation).
Delete all tiny dots in simulation that collide.
Check for every tiny dot that is left, what was the nearest distance to any other dot during orbit. Increase the radius of tiny dot to that minimal distance.
Run simulation again with same positions/velocities but without the dots that had collision and with increased dot size as calculated.
EDIT: I know that it's not how it actually works. It was an answer to "How could I implement this, if I want that behavior on purpose"
Tbh it would probably be simpler to start with exclusively large dots and every time there is a hit, simply shave off exactly as much radius as is needed to prevent that collision the next time. If the dot becomes too tiny, delete it, just to make it not look messy.
If you reduce the radius instead of increasing, you get rid of the whole complexity of figuring out the maximum possible radius based on other dots orbits.
Anyway, both of these approaches might take quite a while to run if the system isn't periodic over a reasonable time-frame.
That is a genius way of getting the same affect, but I would be much more interested in how the above actually works. The above comes from some sort of physics, the ball sizes are predetermined and the engine figures out the optimal paths. That is way more interesting than just forcefully generating this effect.
Wouldn’t you want to increase the radius by half of that tiny distance between them, at least in some cases? Because for the dot that you were minimally close to, it may form a pair where you were the dot that that dot was also minimally close to, so you’d both increase by the distance between you and end up colliding.
Unless it can be proven that no such pair will ever exist (which I don’t think is the case - I mean certainly not with just 2 dots for example because you’d always be minimally close to the other dot because there is no other option).
And then because you’re only increasing by half the distance, you wouldn’t be maximally big in the cases where you didn’t form a pair...maybe you could mitigate this by checking for pairs and adding half when you’re in a pair and full when you’re not which would add a little complexity to each dot calculation (O(the number of dots)) but not much.
Create two sets, one of sin waves of n members, and one of radii r also of n members. Then set the speeds and phases for the particles across the sines such that for each n, only that n is in the neighbourhood +/-r. You'd end up with a bunch of possible speeds and phases for each n, according to their r. You're then limited by the number of particles to include and the speeds you can display. You could probably set it up in 20 or so lines.
No energy loss on collisions means that the total kinetic energy of the system will always be the same. In a real simulation you want kinetic energy losses turning into heat.
Instead of using the formula for gravity, in which the force applied towards the center is proportional to the square of the distance, he used a force that's directly proportional to the distance, linearly. This makes it so that the orbital period of every object will always be the same, so they naturally tend to find a harmony.
So basically as soon as the balls collide with each other, it puts them on different orbits, but since they all orbit harmoniously that dramatically reduces the chances of collisions. If there are any more remaining collisions, they keep moving the balls apart until they no longer collide, so in a few seconds you end up with a system where no balls can collide anymore.
463
u/KillTrot Jun 25 '20
I couldn't even program this on purpose
Edit: He says the same thing in the end of the vid^^