Lab 8 will be collected from your subversion repository on Monday,
November 21,
Work in the file lab8/lab8.rkt. It is important that this file has exactly this name and location; we will be looking for your work under this name at collection time.
This week, you will write a simple kinematics system. You will use it with the 2htdp/universe system to build a real-time simulation of bouncing balls.
We will use the following data definition for a ball:
;; a ball is a ;; (make-ball y v e r c) ;; for y (position above ground of the center of the ball in meters) num, ;; v (velocity in meters per second) num, ;; e (elasticity) num (between 0 and 1), ;; r (radius in meters) num, ;; c color (define-struct ball (y v e r c))We only keep track of each ball's height above the ground (y), making the (unrealistic) assumption that the other two components of the ball's position in three-dimensional space (x and z) remain fixed. The ground is at position 0 and perfectly flat and horizontal, and, in your visualization, the ground should be the bottom of the rendered image.
Given the current position y of the ball, the next position
should be
-
v + g dt when the ball is freely falling (or rising), where g, the acceleration due to gravity, is –9.8 meters per second per second, and dt is 1/28, or, -
if the ball has just struck the ground,
the maximum of 0 and
-ev-f , where e is the ball's elasticity, v is the current velocity, and f, for friction, is 0.5.
In 2htdp/universe, a time event occurs every 1/28 of
a second. At every time step, the simulation must compute a new
position and velocity for each ball. You must implement a
time-event-handling function (say tick) with
type
Implement a function finished? : world -> bool to test if the
simulation is done. A simulation is done when every ball rests on the
ground with velocity 0. You can tell the simulation when to stop
in big-bang with the expression
A world is a list of balls. You can render the world how you like, within reason; in mid-flight, it might look something like this:
Note: when you render the state of the world, you will need to scale the scene to fit in a small window. The model objects in the scene pictured have radii 0.25m, 0.2m and 0.15m from left to right, and they were "dropped" from between around 2 and 3 meters.![]()
Write a renderer, a time-event handler, and a finished-tester,
and put them together into a function