Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

CS 111. Final

Submit your code in Canvas.

You cannot work with anyone on the final! You must add the following statement as a comment in your code: “I confirm that I did not use codes from anyone else and that the work I submit is my own and my own only”. Note that if this statement is not written, the assignment will get a score of 0.

Billard simulation. Suppose that you are starting your job at a game company and your first assignment is to build a billard game. To start, you are only considering two balls (one red and one blue) and focus on their motion on the table, their collisions with the table’s walls and with each other.

To produce a believable motion, you are choosing a physically-based approach, i.e. you start from the equations of motion given by Newton’s second law. Assuming that the friction forces on the table are negligible Newton’s second law of motion gives:

                                    (1)

where x0 is the given initial position. We are also given the initial velocity, v0. Note that v is a vector with two components, i.e. v = (u, v), where u and v are the horizontal and vertical components of the velocity vector v, respectively. The position vector x is defined similarly. Equation (1) can be solved efficiently using an Euler step, as described in class.

In terms of how the balls interact with the billard’s walls or between each other, you are using the following rules:

• When the balls interact with the walls, damping and friction forces apply: The normal velocity is damped by a factor α and the tangential velocity is damped by a factor β. Both α and β are between 0 and 1.

• The interaction between billiard balls is elastic, i.e., after impact, the normal components of the balls’ incoming ve-locities are exchanged, while the tangential velocities are unchanged (see class notes). In this case, there is no friction forces.

Write a Python code that simulates this process using an Euler step with a time step dt = 0.02 to update the position vectors given by equation (1). Make sure that the interaction between the balls and the walls as well as between each other is correct. You may want to set up clear simple examples where you check that those are indeed correct (justify your choices). Then, take a pool table with dimensions [0,1]×[0,1]. The radius of both billiards balls is r = .05. The initial velocity vector is (−.1,.5) for the red ball and (.11,.2) for the blue one. The original positions are (.75,5r) for the red ball and (.25,5.5r) for the blue one. Take α = .8 and β = .98. Run the simulation from t = 0 to tfinal = 50 and display the balls’ motion.

Your grade will depend on how accurately you implement the Euler step (30 pts), the interaction with all the walls (30 pts) and the interaction between the balls (30 pts). The additional 10 pts will be given according to the clarity of the code.

Extra credit: Consider 7 balls instead of 2. If you do this correctly, your grade in the class will change from, A to A+ or B-to B, etc.