The simulation
Running.
- Balls
- 8
- Average speed
- 0
- Bounces
- 0
Four things to try
-
Set Bounce to
1.00and watch the average speed. The balls keep going and the number wanders around one value instead of falling away — nothing in this model takes energy out. It wobbles because a collision can hand most of one ball's speed to another, and that changes the average without changing the total. -
Now set Bounce to
0.60. Every ball settles on the floor within a few seconds. Each impact keeps 60% of the speed it arrived with, and 0.6 multiplied by itself enough times is nearly nothing. -
Set Gravity to
0. The balls drift in straight lines and rebound off the walls forever. That is what "no force acting" looks like, and it is also a decent test that your wall collision code is right. - Push Balls to 24 and watch the frame rate. Every ball is compared with every other one, so the work grows with the square of the count. Twice the balls is four times the work.
What this model gets wrong on purpose
This is a teaching model, not a physics engine. Saying where a model stops being true is part of using one honestly.
- No spin, no friction, no air. A real ball slows down and rolls. These slide forever unless the bounce setting takes their speed away.
- Collisions are resolved one pair at a time. Three balls arriving at the same corner together are handled as three separate pairs, which is not what really happens.
-
Positions are stepped, not solved. The simulation
moves each ball a little every frame. At very high speeds a ball can
step past a wall before anything notices, so the code nudges it back —
look for
separate()insim.js. - All balls have the same mass. That is why the collision maths below is as short as it is. Different masses is challenge 5.