The purpose of this assignment is to practice Problem Solving and Computational Thinking to develop a Python solution to
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
The purpose of this assignment is to practice Problem Solving and Computational Thinking to develop a Python solution to
The force components follow the convention that they are positive when pointing to the right and upwards. Newton's second law thus gives the acceleration of the projectile given by: (5) 17) Update the velocity for every time-step. To get the velocity at the next time step, we make use of the following approximation: (...) = v(.) + act.) At. (6) Then update the positions: f(t) = (t.) + v... ) by(+1) = y(c.) + xy(t. A Note: The velocity magnitude is calculated after each time step, and then the drag force and acceleration are updated accordingly. To find the velocity magnitude at each time step, use the following equation: V = 0;} + vy? Tasks Design and implement a Python program that uses the turtle library to simulate and plot the trajectory of the projectile as shown in the sample runs (Fig. 2). Your program should • Ask the user to enter the angle that the velocity forms with the positive x -axis. The angle must be in the range 20, 60 degrees. • Keep asking the user to reenter if the input is not in the specified range of valid values Fiz 3). Starting with x = 0 and y = 0 at t = 0, we can use the equations (6) and (7) to get the positions for the next time-steps using the velocities found previously • Display on the console the current projectile position, the apex position coordinates, and the range (Fig. 3) Additional requirements: • The simulation area in cyan where the width is 300 pixels and the length is twice its width. • The contour is black, 5 pixels thick (Fig. 2). • Use loops to draw the contour. • The initial position of the projectile should be in the bottom-left corner, which corresponds to the origin • Initialize the parameters as following: M = 2.0 (mass of projectile in kgl. g = 9,8 (acceleration due to gravity in m/s^2), V = 150 (initial velocity in m/s), Cd = 0.005 (drag coefficient), and dt = 0.09 (time step in s} Deliverables Engage first in problem solving and thinking to set up the approach that you will later implement in the computer program. a) Start by defining the purpose of the program, then identify the input and output variables. 2
b) Write down the solution or algorithm in pseudo-code. c) Translate your solution into a Python program d) Last, verify that your program is correct. For that, prepare a test plan. Select at least 3 values for the angle, which correspond to 3 different trajectories. e) Submit a Python source file: pa3_YourID.py. Your file will consist of two parts: (1) header documentation where you define the purpose, input/output data, the algorithm in pseudocode, & test plan, then the Python code Sample runs (a) A projectile with angle 8 = 60 degrees. (b) A projectile with angle 8 = 45 degrees (c) A projectile with angle 8 = 20 degrees. Figure 2: Sample runs Turtle canvas output WELONG TO THE PROJECTELE SECTORY STILATOR Enter the angle (20-65) in der 70 Tvaid it forces Enter the angle (20-0) in degrees 10 Trvallott torces Enter the angle (20-0) in degrees Xy 00 6.522267500000001 11.2173801264906) 12. 63391631660322 21.550553656507507 18.950759253014353 32.3473976950218 411.2390740920954 26.98045110429184 412.68123878905774 17.157625217997656 +3.441774584699) 8.75910332118147 Initial velocity: 150 / Angle: 0.00 Acceleration due to gravity >.8002 Dracottscent: 0.005 Tine step in 0.090 to! The per positionistes are xapex - 256.566. Yap 234.115 The D Figure 3. Sample runs console input/output 3