Head-On Collision
You are part of a team that has been directed to film a head-on car crash for an action movie. You only have the funding for one take! So you must calculate where the crash will occur so that you can determine where to place the camera to get the shot. Look over the code (provided below) and determine:
Once you have answered these questions, modify the code to test your answers.
Note: when conducting this activity with students, the initial positions and velocities of the vehicles can be provided by the instructor, but for demonstration purposes they have been included in the code below.
GlowScript 2.7 VPython #Background Screen Color and Size...***DO NOT CHANGE ANY OF THESE VALUES!! scene.range = 450 scene.center = vector(200,0,0) scene.width = 1000 scene.height = 400 scene.background = vector(0.7,0.7,0.6) #Definition of objects in the system...***DO NOT CHANGE ANY OF THESE VALUES!! ground = box(pos=vector(-120,-10,0),length=1200, height=20, width=20,color=color.blue) redcar = box(pos=vector(-350,10,0), length=40, height=20, width=20, color=color.red) greentruck = box(pos=vector(450,10,0), length=40, height=20, width=20, color=color.green) #Set the velocity for each vehicle redcar.velocity = vector(25,0,0) greentruck.velocity = vector(-40,0,0) #Time and Time step t=0 tf=25 dt = 0.01 #Click Screen to Start scene.waitfor('click') #Calculation Loop while greentruck.pos.x > 0: rate (500) redcar.pos.x = redcar.pos.x + redcar.velocity.x * dt greentruck.pos.x = greentruck.pos.x + greentruck.velocity.x *dt t = t + dt #Text to be displayed on computer screen print ("Time = ",t) print ("Car Position x = ",redcar.pos.x) print ("Truck Position x = ",greentruck.pos.x)
The correctly modified code is shown below, with highlighted areas revealing important modifications.
GlowScript 2.7 VPython scene.range = 450 scene.center = vector(200,0,0) scene.width = 1000 scene.height = 400 scene.background = vector(0.7,0.7,0.6) #define objects in system ground = box(pos=vector(-120,-10,0),length=1200, height=20, width=20,color=color.blue) redcar = box(pos=vector(-350,10,0), length=40, height=20, width=20, color=color.red) greentruck = box(pos=vector(450,10,0), length=40, height=20, width=20, color=color.green) #Set the velocity for each vehicle redcar.velocity = vector(25,0,0) greentruck.velocity = vector(-40,0,0) #Time and Time step t=0 tf=25 dt = 0.01 #Click Screen to Start scene.waitfor('click') #Calculation Loop while greentruck.pos.x > -42.32: rate (500) redcar.pos.x = redcar.pos.x + redcar.velocity.x * dt greentruck.pos.x = greentruck.pos.x + greentruck.velocity.x *dt t = t + dt #Text to be displayed on computer screen print ("Time = ",t) print ("Car Position x = ",redcar.pos.x) print ("Truck Position x = ",greentruck.pos.x)