~~~English~~~ Press the green flag. The three balls will bounce around with gravity, but without any friction or air resistance. The collisions between the balls are perfectly elastic, meaning that all kinetic energy remains as kinetic energy (no energy is lost during a collision). https://en.wikipedia.org/wiki/Elastic_collision ~~~Nederlands~~~ Druk op de groene vlag. De drie ballen zullen rondstuiteren onder invloed van zwaartekracht, maar zonder wrijving of luchtweerstand. De botsingen zijn volkomen elastisch, wat betekend dat alle kinetische energie behouden blijft als kinetische energie (er gaat dus geen energie verloren bij de botsingen). https://nl.wikipedia.org/wiki/Botsing_(natuurkunde)#Volkomen_elastische_botsing
~~~Merren2306 - games & less~~~ ~~~English~~~ To check for collisions I check if the distance between any two balls is less than the sum of their radii (aka, the circles overlap). If that is the case, I calculate how many seconds ago they were touching exactly on the edge. I reverse the balls to that time, then calculate the new velocities the balls will have after the collision. Using this new velocity I move them forward in time by the same amount I moved them back. This way, the accuracy of the collisions is (hopefully) not heavily dependant on the refresh rate. ~~~Nederlands~~~ Om er achter te komen of twee ballen elkaar botsen, kijk ik of de afstand tussen de ballen kleiner is dan de som van hun stralen (in andere woorden, ik controleer of de cirkels overlappen). Als dat zo is, dan bereken ik hoeveel seconden geleden de ballen precies op het randje raakten. Ik breng de twee ballen terug naar dat moment, en bereken dan de nieuwe snelheidsvectoren van de ballen na de botsing. Dan beweeg ik ze weer vooruit in de tijd met dezelfde hoeveelheid als dat ik ze terug had bewogen. Op die manier hangt de precisie van de botsingen (hopelijk) niet veel af van hoe vaak per seconde de simulatie wordt bijgewerkt.