Dog Chasing Mail Truck

Activity Information

Learning Goals

  • Model constant velocity motion
  • Edit a computational model to model a real-world situation.

Prior Knowledge Required

  • Vectors
  • Constant velocity equation

Code Manipulation

  • Create code from mathematical equations

Activity

Handout – Dog Chasing Mail Truck

Oh no! Your dog Booge has escaped his leash and has started chasing after a USPS truck! Thankfully, you’ve previously determined that Booge runs at 4.5 m/s.

  1. If Booge starts at position x = -40 m and runs toward the truck, which is stopped at x = -2.5 m, how long does it take him to get to the truck?
  2. It turns out that the truck is actually driving away from Booge at a constant velocity of 2.5 m/s. How long does it take Booge to catch up to the truck?
  3. There is an invisible fence at x = 40. Does it stop Booge before he gets to the truck?

Computational Model

Here is some starter code to help you model the problem you just solved. Carefully read through the comments in the code to interpret what each line is doing.

4. Input the proper starting positions and velocities for the dog and truck

5. Create lines of code that will update the positions of the dog and truck

6. Change the conditions of the if statements so that positioncheck = False if all of the truck is past the invisible fence or if the dog gets to the rear of the truck

7. How long does it take Booge to get to the truck in the model? How do you know?

8. Why are the results from the purely mathematical model and the computational model different?

Code

Link

GlowScript 3.0 VPython

#name:

#define some things
t=0                     #time in seconds
dt = 0.01               #time increment in seconds
tv=0                    #velocity of truck in meters per second
dv=0                    #velocity of dog in meters per second
dogx=0                  #initial position of the dog
truckx=0                #initial position of the USPS truck
positioncheck = True    #set the value of positioncheck to True

#create some objects
dog=sphere(pos=vector(dogx,0.5,0), velocity=vector(dv,0,0), radius=0.5, color=color.blue, make_trail=True, trail_type="points", interval=50, trail_radius=0.35)                 #create the dog as a blue sphere
truck=box(pos=vector(truckx,1,0), velocity=vector(tv,0,0), length=5, width=2, height=2, color=color.red, make_trail=True, trail_type="points", interval=50, trail_radius=0.40)  #create the truck as a red rectangular box
invisiblefence=box(pos=vector(40,0.1,0), color=color.yellow, length=0.5, width=8, height=0.10, opacity=0.85)                                                                    #create the location of the invisible fence
road=box(pos=vector(0,-1,0),  color=color.gray(0.5), size=vector(100,2,10))                                                                                                     #create the driveway
grassback=box(pos=vector(0,-1,-7.5),color=color.green, size=vector(100,2,5))                                                                                                    #create grass area on the back side of the driveway
grassfront=box(pos=vector(0,-1,7.5),color=color.green, size=vector(100,2,5))                                                                                                    #create grass area on the front side of the driveway

#create a graph
graph(title='Position vs Time', xtitle='Time (s)', ytitle='Position (m)')                   #create the graph
truckgraph = gcurve(color=color.red, width = 5, label='Mail Truck')                         #truck curve
doggraph = gcurve(color=color.blue, width = 3, label='Dog')                                 #dog curve

#set up the view
scene.range=20                                              #make the viewing area a little smaller than the default

#create a loop to make things happen
while positioncheck == True:                                #while statement that will run as long a positioncheck is equal to True
    rate(100)                                               #rate statment to control the number of cycles per second the loop will operate at
                                                            #update position of truck
                                                            #update position of dog

    truckgraph.plot(t, truck.pos.x)                         #plot the graph of mail truck position vs time
    doggraph.plot(t, dog.pos.x)                             #plot the graph of dog position vs time      

    scene.center=vector(truck.pos.x - 20,5,0)               #move the view to follow the truck, with the view shifted toward the negative direction a little

    t=t+dt                                                  #increment the time

    if truck.pos.x < invisiblefence.pos.x:                  #check to see if the truck has reached the invisible fence
        positioncheck=False                                 #if true change positioncheck to false to stop the while loop
    if truck.pos.x=0:                                       #check to see if the dog has reached the truck
        positioncheck=False                                 #if true change positioncheck to false to stop the while loop

Answer Key

Handout

1. To find this time, we can use the constant velocity equation: v = d/t. Rearranged for time, this equation is: t = d/v. To find Booge’s displacement, we can subtract his final position from his initial position. His velocity is 4.5 m/s is given.

d = xf - xi => d = -2.5 - (-40) = 37.5 m
t = d/v = 37.5/4.5 = 8.3 s

It takes Booge about 8.3 seconds to reach the stopped truck.

2. To solve for this, we can write two position equations, one for the dog and one for the truck, using the equation x = xi +vt. We then can set them equal to each other because we want to know when they will have the same position:

x(truck, initial) + v(truck)*t = x(dog, initial) + v(dog)*t
=> t = (x(truck,initial)-x(dog, initial))/(v(dog)-v(truck)) = 18.75 s

3. To solve for this we plug the time found above into the equation for booge’s position:

x(dog) = x(dog,initial) + v(dog)*t = 44.375 m

The fence will stop Booge before he gets to the truck’s position.

4. The proper starting velocities and positions in the code look like this:

tv=2.5                #velocity of truck in meters per second
dv=4.5                  #velocity of dog in meters per second
dogx=-40                #initial position of the dog
truckx=-2.5             #initial position of the USPS truck

5. For this part, we need to use the constant velocity equation solved for position: Δx = vΔt. In the code we can say that the new position is equal to the current position plus the change in position, which is vΔt. This means that our equations in the code end up being:

truck.pos.x = truck.pos.x + truck.velocity.x*dt    #update position of truck
dog.pos.x = dog.pos.x + dog.velocity.x*dt          #update position of dog

6. For the first if-statement, the entire truck needs to be past the invisible fence for the code to stop running. To check this, we can subtract half the length of the truck from its position:

    if truck.pos.x - 2.5 > invisiblefence.pos.x:            #check to see if the truck has reached the invisible fence
        positioncheck=False   

For the second if statement, we want to see if the dog and the truck are within 3 m of each other. To do this, we can take their separation vector: truck.pos.x – dog.pos.x and check if it is ever less than or equal to 3 m:

    if truck.pos.x - dog.pos.x <= 3:                        #check to see if the dog has reached the truck
        positioncheck=False 

7. To find this out, we can add print statements to the code, that will print the time when positioncheck becomes false.

8. In question 3, we found when the dog and the truck have the exact same position. The computational model, on the other hand, checks for when the dog gets to the rear of the truck, which lessens the distance Booge has to travel before reaching the truck.

Code

Link

GlowScript 3.0 VPython

#define some things
t=0                     #time in seconds
dt = 0.01               #time increment in seconds
tv=2.5                  #velocity of truck in meters per second
dv=4.5                  #velocity of dog in meters per second
dogx=-40                #initial position of the dog
truckx=-2.5             #initial position of the USPS truck
positioncheck = True    #set the value of positioncheck to True

#create some objects
dog=sphere(pos=vector(dogx,1.0,0), velocity=vector(dv,0,0), radius=1, color=color.blue, make_trail=True, trail_type="points", interval=50, trail_radius=0.35, trail_color = color.white)                    #create the dog as a blue sphere
truck=box(pos=vector(truckx,1,0), velocity=vector(tv,0,0), length=5, width=2, height=2, color=color.red, make_trail=True, trail_type="points", interval=50, trail_radius=0.40, trail_color = color.yellow)  #create the truck as a red rectangular box
invisiblefence=box(pos=vector(40,0.1,0), color=color.yellow, length=0.5, width=8, height=0.10, opacity=0.85)                                                                                                #create the location of the invisible fence
road=box(pos=vector(0,-1,0),  color=color.gray(0.5), size=vector(100,2,10))                                                                                                                                 #create the driveway
grassback=box(pos=vector(0,-1,-7.5),color=color.green, size=vector(100,2,5))                                                                                                                                #create grass area on the back side of the driveway
grassfront=box(pos=vector(0,-1,7.5),color=color.green, size=vector(100,2,5))                                                                                                                                #create grass area on the front side of the driveway

#create a graph
graph(title='Position vs Time', xtitle='Time (s)', ytitle='Position (m)')                   #create the graph
truckgraph = gcurve(color=color.red, width = 5, label='Mail Truck')                         #truck curve
doggraph = gcurve(color=color.blue, width = 3, label='Dog')                                 #dog curve

#set up the view
scene.range=20                                              #make the viewing area a little smaller than the default

#create a loop to make things happen
while positioncheck == True:                                #while statement that will run as long a positioncheck is equal to True
    rate(1000)                                               #rate statment to control the number of cycles per second the loop will operate at
    truck.pos.x = truck.pos.x + truck.velocity.x*dt         #update position of truck
    dog.pos.x = dog.pos.x + dog.velocity.x*dt               #update position of dog

    truckgraph.plot(t, truck.pos.x-2.5)                     #plot the graph of mail truck position vs time
    doggraph.plot(t, dog.pos.x+0.5)                         #plot the graph of dog position vs time      

    scene.center=vector(truck.pos.x - 20,5,0)               #move the view to follow the truck, with the view shifted toward the negative direction a little

    t=t+dt                                                  #increment the time

    if truck.pos.x - 2.5 > invisiblefence.pos.x:            #check to see if the truck has reached the invisible fence
        positioncheck=False                                 #if true change positioncheck to false to stop the while loop
        print("The USPS truck got away at t = ",t)
    if truck.pos.x - dog.pos.x <= 3:                        #check to see if the dog has reached the truck
        print("The dog got to the truck at t =",t)
        positioncheck=False                                 #if true change positioncheck to false to stop the while loop