myphysicslab – colliding blocks
this simulation shows two blocks moving along a track and colliding with each other and the walls. one spring is attached to the wall with a spring. try changing the mass of the blocks to see if the collisions happen correctly.
you can change parameters such as mass, spring stiffness, and friction (damping). you can drag either block with your mouse to change the starting positions. if you don't see the simulation try instructions for enabling java. scroll down to see the math!
collisions and conservation of momentum
the spring and block on the left use the same model as the single spring simulation
. for a collision with the wall, we simply reverse the velocity. for collisions between moving blocks we use the law of conservation of momentum to determine the new velocities.
define the following variables:
- v1i, v2i = initial (pre-collision) velocity of blocks
- v1f, v2f = final (post-collision) velocity of blocks
- vcm = velocity of center of mass
- v1cm, v2cm = velocity of blocks in center of mass frame
- m1, m2 = mass of blocks
- pi, pf = initial and final momentum of system of blocks
we find the velocity of the center of mass of the 2-block system.
m1 v1i + m2 v2i
m1 + m2
next we find the velocity of each block in the coordinate system (frame) that is moving along with the center of mass.
v1cm = v1i − vcm
v2cm = v2i − vcm
next we reflect (reverse) each velocity in this center of mass frame, and translate back to the stationary coordinate system.
v1f = −(v1i − vcm) + vcm
v2f = −(v2i − vcm) + vcm
if you fully expand the above you get
v1f = −v1i +
2(m1 v1i + m2 v2i)
m1 + m2
v2f = −v2i +
2(m1 v1i + m2 v2i)
m1 + m2
as a check, we can calculate the pre- and post- collision momentum, which should be the same.
pi = m1 v1i + m2 v2i
pf = m1 v1f + m2 v2f
if you expand pf
using equations (1) and (2) and simplify you will see that pf = pi
handling collisions in software
simulation of two balls colliding
simulations on the computer are discrete in the sense that time advances in "chunks", not smoothly. in the diagram, we calculated the state of the world at time t = 10.0
and then at time t = 10.1
. but the collision happened sometime inbetween. so by the time we detect a collision, the objects are overlapping each other -- a physically impossible state.
the simulations on this website handle collisions as follows:
- detect that a collision occurred
- re-run the simulation to very close to (but just before) the time of collision. the time of collision is found by a binary search process.
- handle the collision by modifying the state of the simulation, such as fixing the velocities as described above.
- continue to run the simulation up to the current 'now' time. if additional collisions happen they are handled in the same way.
if you are not running the simulation in real time, you can take as long as you want to get as much accuracy as desired. but for a real time simulation, you may need to accept lower accuracy or use some fancier programming. for example, instead of using trial and error to find the time of collision, you could try to predict the time of collision based on the state of the system.
other examples of collision handling are the simulations roller coaster with flight
and rigid body collisions