Any help is appreciated. Im having a hard time understanding the problem. All the files in the zip are pasted here.
Gas Simulation In this problem, we consider a simulation of n bouncing balls in two dimensions inside a square box. Each ball has a mass and radius, as well as a position (113,31) and velocity vector, which they follow until they collide with another ball or a wall. Collisions between balls conserve energy and momentum. This model can be used to simulate how the molecules of a gas behave, for example. The world is 400x/ by 400% units wide, so the area is proportional to the number of balls. Each ball has a minimum radius of 16 units and a maximum radius of 128 units. Download ps3_gas .zip from the class Sakai site. For the graphical interface to work, you will need to have pygame or tkinter installed. They currently run slightly different interfaces. Feedback is appreciated. You may notice that performance, indicated by the rate of simulation steps per second, is highly dependent on the number of balls. Your goal is to improve the running time of the detect _collisions function. This function computes which pairs of balls collide (two balls are said to collide if they overlap) and returns a set of ball_pair objects for collision handling. You should not need to modify the rest of the simulation. (If you think something else should be modied, email me with your feedback.) (a) (3 points) What is the running time of detect_collisions in terms of n, the number of balls? (b) (8 points) Argue that the following algorithm is asymptotically faster: Divide the world into square bins of width 256. For each ball, put it in its appropriate bin. Then for each bin, check for collisions where either both balls are in the bin, or one ball is in the bin, and the other ball is in an adjacent bin. (c) (28 points) Implement the detect_collisions algorithm described in part (b). Put your code in detection.py, and uncomment the line in gas .py just below detect_collisions that imports your new code. Your new code must still nd all the same collisions found by the old code (any pair of balls for which colliding returns true). To check that you are detecting the same collisions, run your code and the original code with the same parameters, and make sure that they detect the same number of collisions. In your documentation, do not assume that the reader has read this problem set. Submit detect ion.py to the class Sakai site. ((1) (3 points) Using your improved code, after 1000 timesteps with 200 balls, how many collisions did you get? How many simulation steps per second did you run? How many simulation steps per second could you run with the original code and the same number of balls