Colliding Crates
In this activity, you will be asked to complete several tasks involving what you have learned about describing motion and applying this knowledge to actual computer program code. In describing motion at this point, we need to consider both position and velocity. To keep this activity simpler, you will be working with constant velocity, either positive or negative.
First, you will need to go to GlowScript.org and create your own free account to begin adapting the computer code listed below. Next, select “create a new program” and copy and paste the code below to begin your adventure. Make sure you copy all of it.
GlowScript 2.7 VPython #Creating the objects floor = box(pos=vector(0,-30,0), size=vector(100,4,12), color=color.white) #I've created the floor that the crate will slide across crate = box(pos=vector(0,0,0), size=vector(20,20,5), color=color.red) #I've created the crate, along with its dimensions and initial position resting on the floor #Setting the time interval t=0 #I've set the initial time to zero. tf=0.940 #I've set the final time to 0, which gives the crate enough time to slide across the floor dt=0.01 #I want my time interval set at 1/100th of a time unit #Creates velocity vectors as a function of time get_library('https://rawgit.com/perlatmsu/physutil/master/js/physutil.js') #The program needed to know what a motion map is defined as motionMap = MotionMap(crate, tf, 5, markerScale=0.1) #I want to display 5 arrows showing the motion of the crate #Giving the objects an initial velocity cratev=vector(75,0,0) #I'm defining the constant velocity of my crate to be 75 in the x-direction(left to right) while crate.pos.x<35: #I want the crate to stop before it slides off the floor rate(50) #This rate can speed up or slow down the replay crate.pos=crate.pos+cratev*dt #I'm moving the crate by adding the change in position (cratev*dt) to the previous position (crate.pos) t=t+dt #I'm updating the time #This updates the velocity vectors motionMap.update(t,cratev) #This updates the motion map and display of the arrows as the crate slides across the floor #This creates the graph of the kinetic energy of the crate f1 = gcurve(color=color.blue) #Setting up a graph to show the kinetic energy of the crate as a function of time for t in arange(0, 0.94, 0.01): # Time goes from 0 to 0.94 in 0.01 time intervals f1.plot(pos=(t,cratev.mag**2)) # plot time vs. kinetic energy of the crate
GlowScript 2.7 VPython #Creating the objects floor = box(pos=vector(0,-30,0), size=vector(100,4,12), color=color.white) #I've created the floor that the crate will slide across crate1 = box(pos=vector(-40,-20,0), size=vector(20,20,5), color=color.red) #I've created the crate, along with its dimensions and initial position resting on the floor crate2 = box(pos=vector(40,-20,0), size=vector(20,20,5), color=color.blue) #Setting the time interval t=0 #I've set the initial time to zero. tf=0.940 #I've set the final time to 0, which gives the crate enough time to slide across the floor dt=0.01 #I want my time interval set at 1/100th of a time unit #Creates velocity vectors as a function of time get_library('https://rawgit.com/perlatmsu/physutil/master/js/physutil.js') #The program needed to know what a motion map is defined as motionMap1 = MotionMap(crate1, tf, 5, markerScale=0.1) #I want to display 5 arrows showing the motion of the crate motionMap2 = MotionMap(crate2, tf, 5, markerScale=0.1) #Giving the objects an initial velocity crate1v=vector(25,0,0) #I'm defining the constant velocity of my crate to be 25 in the x-direction(left to right) crate2v=vector(-15,0,0) while crate2.pos.x-crate1.pos.x>20: #I want the crate to stop before it slides off the floor rate(50) #This rate can speed up or slow down the replay crate1.pos=crate1.pos+crate1v*dt #I'm moving the crate by adding the change in position (cratev*dt) to the previous position (crate.pos) crate2.pos=crate2.pos+crate2v*dt t=t+dt #I'm updating the time #This updates the velocity vectors motionMap1.update(t,crate1v) #This updates the motion map and display of the arrows as the crate slides across the floor motionMap2.update(t,crate2v) #This creates the graph of the kinetic energy of the crate f1 = gcurve(color=color.blue) #Setting up a graph to show the kinetic energy of the crate as a function of time for t in arange(0, 0.94, 0.01): # Time goes from 0 to 0.94 in 0.01 time intervals f1.plot(pos=(t,crate1v.mag**2)) # plot time vs. kinetic energy of the crate