Bouncing balls programming laboration
This module contains of just one problem: to simulate a model of a dynamical sytsem.
(BOUNCING BALLS PROBLEM)
Implement a program that simulates two balls bouncing around a 2D rectangular space under the influence
As a starting point, download this Java code. You do not need to change the code in Animator.java: this code displays the balls
on the screen. We give you this code so you can concentrate on the part of the code that does the modelling, in Model.java
Note: Before you do anything else, please try to compile and run the given code, and ask for help if you cannot get it running on your machine.
You will use
to simulate the movement of the balls. Let the balls have different sizes and weights. The equations for the movement are the following:
See this note with
bouncing ball calculations for more details.
- For the free moment in the air, the vertical position y changes
according to y'' = -g under the influence of gravity (this is where
you need to simulate the differential equation). For the horizontal
position x there are no forces so x''=0.
- If no collision occurs, then we update the ball's velocity and position as follows:
x(t+dt) = x(t) + x'(t) * dt
y(t+dt) = y(t) + y'(t) * dt
x'(t+dt) = x'(t) + x''(t) * dt
y'(t+dt) = y'(t) + y''(t) * dt
- A collision with the walls simply reverses the sign of the
perpendicular to the wall.
- A collision between the balls can be calculated in the following way.
with collision with a wall, the velocity tangential to the surface of
the ball is
not affected. The velocity along the line between the centre of the
is changed under conservation of the total kinetic energy mv^2/2 and
mv of the two balls. Begin by trying with the simple case of two equal
balls. (Note that to do this calculation you must make a change of
coordinates. An easy way to do this is to implement the subroutines rectToPolar
and polarToRect and debug these
before you use them!)
HINT: Some groups have trouble with this problem
because they do not plan their problem solving and are not careful with details.
First think and determine exactly what it is you need to calculate in
each step, and make sure you understand what you are doing. Draw appropriate
figures, define appropriate quantities etc.
- When your code is ready, please demonstrate your code to a supervisor. Use the topic 'Demonstrate BB' on waglys to request this.
- Please submit your Model.java file through FIRE by Sunday 6 September.
- If you have not demonstrated your code to a supervisor before Sunday, please submit your code and then demonstrate it to a supervisor next week.
- There is no follow-up lecture for this module, but after Sunday we will publish a note containing some questions and topics to think about during your reflection.