Also... Hmmmm... Yea I guess it is a bug... But you only forgot to add a slight friction, or loss of energy transferred on collision, haven't you? So colliding items will always end up using another trajectory until they don't collide anymore. It's a universe without energy loss to friction/deformation.
When you try to make a collision handling system, but just end up making a system that has no collisions at all... Technically, you've solved the problem.
@@kaidatong1704 The n in O(n) is a variable that means the number of items to be handled. If n is constant then it's not O(n) time, it's O(1) (constant time) because the time to run doesn't depend on the number of items. You don't set constant values for n. O(0) is just a joke, since in a collision-free system you wouldn't even implement the function and thus is it would never actually take any time at all.
Holy crap The precision in which these weren't coliding is insanely satisfying Hope you saved a version of your code with the "bug" and called it "art mode"
@@sirpsionics no they were not, it was just so close you would have to zoom a lot to see they actually don't touch. Cuz if they did it wouldn't be this smooth
@@alexstasko696 I also think they become red upon touch. But I think he's right, sometimes they touch ever so slightly but the hitbox is too imprecise, that's my guess anyway.
I'd love to see an in-depth video explaining the mechanics behind this behaviour. As collision avoidance has such wide reaching & valuable applications it seems almost certain that this has already been discovered & no doubt named.
They push each other with constant force until they stop colliding, which requires producing energy out of nowhere. He just messed up conservation of momentum in his calculations.
i can imagine that if someone wanted to create a system where given any radii and position parameters had the task to find a stable orbit relationship without any collisions, it would be really difficult without the use of a neural network (and probably still really tough), but the fact you got this behavior via a bug is just hilarious. and the concept has a lot of potential as a game too. with planets… or somethin haha
Well in this case there’s no gravitational interaction between the bodies, they just have a single attraction point that stay stable in position and magnitude over time
If I understand the code, each ball is attracted by the center through an elastic force, while collisions directly displace pairs of overlapping particles away from each other in such a way that they end up barely touching, without modifying either of the registered speed values. Each ball has the same mass, so the period of each orbit is essentially the same, as a result the whole dance will stay in sync once the particles trajectories have been tuned to avoid overlapping. As far as I can tell, the speed itself is never updated by anything but the force, only the time-step size changes, that part is confusing but I guess that the simulation slows down when particles collide. However that would result in infinite acceleration toward the center would the particles jam upon each other so I may have missed something.
I don’t think the simulation slows down when the particles collide. To me, it looks like the particles temporarily slow down while they are pushing each other, and once they are free, they go back to their old speed
3 года назад
This guy: Hey, that's not what I meant to do Bug: It would be a lot cooler if you did
It's a sort of accidental evolutionary process, the orbits that don't have collisions survive while those that do get mutated into a different orbit where they get tested again. Very good example of emergence.
I'm shocked. A few months back I decided to try to implement a collision system myself for fun, although the particles would look ahead, and if it saw the trails of any previous particles it would turn in a direction away from it. I randomly picked different wells of different strengths around the plane for the particles to have something to keep them from just bouncing against the walls, and the end result was basically this similar group weaving and bobbing, but the groups would collectively migrate to different parts of the screen. It wasn't what I was going for, but since I had written it where it could handle 10M particles, I loved what I ended up with that I never even considered "fixing it".
He just forgot to add code to update the speed so the object move with 0 energy loss and eventually bounce off each other in a way that causes no new collisions quite simple and im sure most people that were trying to make a collision system have found a movement bug related to this exact bug, hes just probably the first to do it like this
@@nothingnothing1799 I think there must be a second error made as well. All of these take the same amount of time to complete their orbit, no matter how big their orbit is.
@@ekkehard8 I think that all the balls start moving at the same speed, and typically when they collide you would calculate the amount to slow them down by the balls mass (or aproximate it using their size) to have energy conservation.
@@ekkehard8 Not a physics error though, a test quirk. There is an inward force as part of the test, and it looks to be linear with respect to distance and mass, turning them into simple harmonic oscillators. This is the same physics that is used for almost all clocks. If anything it speaks to the accuracy of the physics code that an oscillator works accurately enough for this to be stable!
@@TH3RM4L You seem to have missed completely the quote by Isaac Asimov "The most exciting phrase to hear in science, the one that heralds new discoveries, is not 'Eureka!' but 'That's funny...'" The value isn't necessarily monetary, the value might be progress of humankind.
@@ehsnils idk why you talking about asimov, but when Ive looked at other comments, they talk about wanting to pay for this as a feature in some program. Ie, capitilaism has invaded even eureka moments like this
This feels like those videos of a city traffic stop that's full of pedestrians, bikers, and cars all moving right past one another, just barely skimming without any accidents
Man, it's satisfying to see how objects are flying soooooo close to each other it seems like they're scratching each other, but yet they don't collide at all.
This is incredible! I can imagine somewhere someone wanted to intentionally set out to make something that looked like this, but the animation required to hand create something like this would take a quite a while! So cool to see something this beautiful come from coding.
So I read the code, and I would summarize it like this: basically he didn't implement velocity update when collision happens. When collision is detected (with simple radius check), he just nudged both of the spheres back away from each other just enough that they touch. The end effect is that they slide off of each other, continuing on their original path. So its like inelastic collision with no friction? Anyway it's these unique ingredients that drive the system to a stable state with no collision. Very cool!
Thank you so much for an actual explanation from reading the code. There are so many comment trains here with wild speculations that I can't parse enough to figure out if they are valid or not. I was thinking I would have to grab the code myself and see, but you beat me too it.
Thats what I was thinking was going on, they are kind of acting like billiard-balls, where in reality some of the energy would dissipate as heat, here it simply perfectly transfers to the colliding objects.
@@xdlmaoooo No they aren't transferring energy to each other, that's the problem. They're ignoring each other's velocities, only slightly nudging each other enough to slide past without overlap.
is this right: the two colliding circles change each other's *positions* without changing either one's speed/direction/mass/etc? What happens in a near head on collision?
My guess is that there's no velocity loss with any of the balls after they collide. So the balls fall to the centre and orbit around it and the collisions between each other are correcting their path until eventually, over time the balls develop paths that don't collide with any other ball or barely slide past one another. Cool bug.
@@JackGF936 Like I said fully elastic collisions alone (which fully conserve energy) isn't enough to produce this system state - the balls would just keep bouncing randomly forever. And neither are elastic collisions that generate energy, that just increases"orbital eccentricity" with every bounce thus reducing density and by extension the odds of collision, but doesn't moves anything into specifically collisionless trajectory. I invite you to attempt to replicate such result in a properly written physics simulation engine using any parameters you want - this scenario won't happen, other forces than restitution adjusted impact normal are required to achieve this effect.
@@michaelbuckers I think I have a simple counter-argument for your claim here: The balls basically try out different trajectories. If the ball does not have a free trajectory, it will collide. This will change the trajectory, and the ball will try a slightly altered one. This process will continue until all balls have free trajectories. After that we will see the behavior demonstrated in the video. I can not see how the system would converge to a "random bouncing state" you are suggesting there. (Or at least that is higly improbable with randomish start state.) The free trajectory state is the only one that does not change itself, so I am pretty sure the system will converge to that one. Also, I challenge you to produce this random bouncing state you claim will occur.
@@IlariVallivaara You're talking out of your ass. It doesn't even looks like you ever seen the elastic collision equation in your life. Go take a look at it and point out literally anything about it that suggests that any system of moving bodies will converge to a collisionless state, you massive dunce. Your challenge has been already complete: molecules of air never stop bouncing, objects in the solar system never stop colliding.
These happy accidents are my favourite thing in programming, you can get endless hours of fun just by playing around and exploring its details. It's like going on an unexpected adventure
@@DavidFong21 Their name is whispered is the hall of legends ;) But for real, Sebastian probably makes my favourite content on YT, mind-blowing every time!
Especially at 2:27, seems like all their gravitational pulls have synchronised somehow. Search up Dyson Swarms, It's an idea where there are many orbiting solar panels around a star, which could provide enough energy for a type 1+ civilization (more advanced than our own). This technique could solve the problem of collisions between these panels. Sounds a bit crazy perhaps, but I think this technique could be very useful when implemented properly.
@@marzipug5439 Okay, but hear me out. The way this works is they keep crashing into each other until their orbits stabilize. I don't think that's viable to do with solar panels.
@@Shmill That's where this piece of software comes in handy to precalculate! 😁 Theoretically. Guess you'd prefer a bit of space between fast moving chunks of metal that won't keep their precise orbit in reality. 🤔
That is mind bending. I think it broke my brain. Can't even imagine how all the dynamics worked to provide what appears to be stable non-colliding orbit paths.
I legitimately spent hours trying to find this video the other day, I thought the effect was so cool but I had absolutely no idea what it was called. Eventually gave up. Now here it is in my recommendations. The world is weird.
I might be wrong but I think the reason this happens is that there's no loss of momentum when they collide just a change of the direction of momentum, so what happens is that they push each other out of the way but continue to move at the same speed, just in a different direction, which eventually causes the system to become stable.
came to the same conclusion, no velocity is lost. However, collisions don't change their direction, instead they just nudge eachother while keeping their original direction. The other essential condition is that their size don't impact their speed, so once two balls have moved out of each other's respective paths, they'll never collide again unless they're moved by other balls.
This simple principle has wider applications..... In cases bound by Newtonian physics, should you inject enough energy into a media to overcome friction, but not entropy, it will eventually systematize so as to obey physics in the most efficient manner, causing the media to be more orderly. An example would be the "Frito's Bag" which claims that the chips in the bag may have settled in shipping, causing the air gap in the bag. The result is that the chips are stacked more orderly in the bottom of the bag than they were originally filled at the factory. Call it the "Lays Bag Theorem" ; P. This can be useful in manufacturing, medicine, and .... I just realized that's the principle behind the electrotreatment my GF receives for her nerve damage. I mean, I should probably finish my degree so I can learn exactly what this is called because I doubt this is original.
The satisfying feeling that comes from seeing the old DVD player screensaver hit pixel perfect in the corner.. you know what I'm talking about.. it appears you've accidentally created an infinite loop of that very sort of satisfaction.. hnng~ Someone get this person a lifetime achievement award.
You will see your share of weird shit, trust me. My funniest was a 200ish line function that I wrote while rather absent minded. I ran it, it worked perfectly. After running it for a really really long time it returned an answer that was obviously wrong. I thought the bug cant be that complicated as it otherwise did exactly what was expected. Looking at it I found many totally obviously wrong conditionals. Swapped AND's and OR's, < in stead of >, lookups in the wrong spot of an array. All easy to fix but in stead I sat there for some 30 min wondering how it ever produced a correct result. There was some mad unexpected recursion going on where n wrongs made a right. I couldn't figure it out. Probably the most complicated code I ever read. (I use to write machine code) It was all so obviously wrong my theory is that some higher entity took over my hand and made a joke.
@@ZLP-TM it may appear that they are touching because of the technical limitations of your display but if the calculations are correct, there should always be some space between the circles.
@@creampielover69 They definitelly touch and slow down, watch closely. Thats mostlikely because he didnt run his program for long enough, it takes time for them to settle in
This would be the dopest looking main menu wallpaper of a futuristic space sci-fi game where traffic/travel is a thing, like in GTA or cyberpunk. You would see hundreds of spacecrafts just perfectly travelling through this portal intersection etc. (the tightest turn being the portal)
This is amazing. It's almost like there is some "self-optimization" that is occurring. The first time they come into contact, they slide past each other and then orient themselves in such a way that they don't ever touch when they come back around. Pretty cool.
Well not the first time, in the big one it took like half an hour to happen. I suspect he forgot to implement some kind of friction to make things actually eventually stop, and then the can just keep bouncing until they reach some stable configuration where they slide just past each other
The man tried to make a collision system, but instead made a chaotic orbit creator. Imagine if those dots were planets and how beautiful yet scary it would be to live there.
In 23 days mars will have a close approach of 5 meters over northern France. Due to this everything north of Béthune and Roubaix will be evacuated. Anyone Living in Belgium, Netherlands or north of Paris is advised to spend the day underground.
Would be very cool. Though it wouldn't work since this simulation doesn't include gravity between the bodies. Also, I don't think you would want to experience the tidal waves created by that! :) Another unfortunate thing is that gravity would (approximately) cancel out when the planets were at their closest. Lots of weird stuff would basically happen!
This is cool! I saw your initial upload two weeks ago. I downloaded your code and tried to understand what makes this effect emerge. There is a comment under your previous video explaining that this effect happened because you updated only the positions and not the velocities of the colliding sphere. This is true and I think it is indeed part of why the system is not chaotic (in the mathematical sense: small errors on the initial velocities are not amplified by the collision since you do not update them). I would like to add that there is something else that is very important for it to work. It is that you are using a force that is linear in the distance to the centre (like a spring). It has the nice property that all the particles will oscillate around the centre with oscillate with the same frequency and thus the trajectories can remain independent. If you add a small non-linear term in r (e.g. 1e-6*r^3) the oscillations are non synchronized and the particles end up colliding again. It is the collision code that forces the particles to follow independent trajectories but it is the specific nature of the force that let the particles keep their independence. This is indeed a nice "bug". It would be interesting to find an application for this, but I cannot think of any in physics because these collisions do not obey the conservation of momentum. Maybe it can still be used to find an suitable initial configuration for a physically correct simulation. Otherwise I saw requests for a screensaver, this is a good idea too :) PS: Happy to see another user of the SFML library!
I changed the code to make the attraction force proportionnal to the radius of the objects and in this case the orbits tend to become concentric circles. And yes I love SFML, I use it for all my projects :)
I was so excited about this for a few minutes before reading this comment. I thought it was an automatic many body problem solver, but then that requires simulated gravity to be a thing.
Hooray I was looking for the people who noticed this, I see you're all here. Concentric circles would make sense in that case, without the global periodicity imposed by the linear force, that would seem to be the most natural way to get a stable solution. I would be curious to see if that also happens if you use a Newtonian potential
It looks like the inward force is linear with distance and mass, turning them all into simple harmonic oscillators. The orbital period is fixed, irrespective of orbital parameters. It is the same physics as a pendulum, that swings in the same time no matter how heavy the mass or distance of the swing.
Some of the greatest things invented were accidents. Penicillin, Teflon, post it notes and corn flakes just to name a few. It happens from time to time and if it does it's just so satisfying. Glad that happened for you!
This reminds me so much of stars orbiting Sagittarius A* that it hurts my head. It seems like a 2D representation of 3D spheres in orbit around the centre. Kind of mesmerizing.