Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Any help is appreciated. Im having a hard time understanding the problem. All the files in the zip are pasted here.

image text in transcribedimage text in transcribed
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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions