Tutorial 9: 1D Collision Detection and Reaction
1D Collision Detection and Response
In the lectures 1D collision reaction has been discussed here.
The wikipedia entry for momentum has the same formulae as in the notes, but with different variables for initial and final velocities, e.g. for elastic collision:
Where u (or ui) is the initial velocity and v (or vi) is the final velocity.
Note: The above equations are for the case of 1D only.
Elastic Collisions
- Compile and run this 1D collision program. Experiment with some sensible values for initial velocities and masses and check if what is displayed seems correct.
- Like most of computer graphics, visual debugging for collisions is essential. Modify the program so that disks change colour when they are colliding.
- For (game) physics, another type of debugging is to check whether physical quantities are being conserved. In elastic collisions momentum and kinetic energy are both conserved. Add functions sumKinetic and sumMomentum. Use those functions to print values out and check that quantities are being conserved. Are they?
- Also put a check for quantity conservation in your program.
- Modify the 1D collision program to calculate disks’ radii in proportion to mass using area (try volume as well, since it may work better for the assignment).
- Modify the 1D collision program to allow a variable number of particles. Create a function initDisks(int n) which generates random positions and masses. Things will break if disks overlap to begin with. And things will likely break when there are lots of disks.
- For a smallish number e.g. 10 disks, again check if kinetic energy and momentum are being conserved.
Inelastic Collisions
- Modify the program to support completely inelastic collisions for two disks only. When an inelastic collision occurs the objects involved stick together. Handle that by calculating for one of the disks a new radius proportional to the sum of the masses. Mark the other disk as absorbed, i.e no longer to be considered (and means no need to use dynamic data structures for this exercise).
- Are kinetic energy and momentum being conserved now?
- Modify the program so that it supports a variable number of disks. Simply ignore absorbed/marked disks.
2D Elastic Collisions
- Left as an exercise
2D Inelastic Collisions
- Try modify the 1D collision program to handle 2D inelastic collisions. Start with just two disks, and assign them sensible initial values. Remember, solve the collision equations separately in x and y.