02-A Monkey and Bananna

A classic physics demonstration on the motion of objects under the influence of Earth’s gravity is often called the Monkey and Gun or Monkey and Hunter demo. Here are some interesting links about this demo.

In this exercise, you will simulate this demonstration using VPython.  In the spirit of being politically correct we will assume that we have a Zookeeper who is sending a banana to a monkey using an air cannon.  Suppose the banana can be launched with a speed of 15 m/s and that the monkey, who is startled by the noise from the air canon, releases from its branch at the same instant that the banana is fired.

Modify the code provided below to include the appropriate physics to govern the motion of the banana and the monkey.  It is very crucial that you provide an initial momentum for the banana that is aimed directly at the monkey in order for the banana to make it to the monkey.

The code is set up to continue running until the banana and the monkey are at the same position (really within 5 mm of each other) or the monkey hits the ground.

Areas requiring your attention are highlighted with large comment boxes and instructions.  You will need to set the initial positions of the monkey and banana, set the initial momentum (vector) of the banana, define the forces on the monkey and banana, and update the momentum and the position of both the monkey and banana inside the loop.

When your application is completed you should be able to change the initial position of the monkey or of the banana in only one location and still be able have the banana hit the monkey.

Have fun feeding the monkey !

# Recreate the famous Monkey and Hunter classroom physics demonstration

# Set the background color to a medium gray so the monkey and banana are more visible
grey = vector(0.6,0.6,0.6)
scene = canvas(background=grey)

# Define an object to represent the monkey
monkey = sphere(texture="https://i.imgur.com/KJ3EWKc.png", emissive = True,
                make_trail = True, trail_type = "points", trail_radius = 0.03, 
                opacity = 0.5, interval = 20)

monkey.radius = 0.25            # Size of the monkey in m
monkey.m = 15.0                 # Mass of monkey in kg
monkey.p = vector(0,0,0)        # Monkey is initially at rest.
monkey.pos = vector(1,1,0)      # Initial Position of Monkey

# Define an object to represent the banana
banana = sphere(color=color.yellow, make_trail = True, trail_type = "points", trail_radius = 0.03, interval = 20)

banana.radius = 0.05            # Size of the banana in m
banana.m = 0.2                 	# Mass of the banana in kg
banana.pos = vector(-1,0,0)    	# Initial Position of the banana

##############################################################################
#                                                                            #
# 1. Set initial positions of the monkey and banana above to given values.   #
# 2. Define the initial momentum of the banana so that it will be aimed      #
#    at the monkey.                                                          #
#                                                                            #
##############################################################################

banana.p = vector(0,0,0)

MyGraph = graph(title = 'Trajectory: Y vs X', width = 800, height = 400,
                xtitle = 'Vertical Position (m)', ytitle='Horizontal Position (m)', 
                background = grey, fast = False)
                      
MonkeyTrajectory = gcurve(color = color.black,  width = 2, label = 'Monkey Position')
bananaTrajectory = gcurve(color = color.yellow, width = 2, label = 'Banana Position')

g = 9.8                         # Acceleration due to gravity in N/kg

##############################################################################
#                                                                            #
# 3. Define correct expressions for net forces on the Monkey and Banana.     #
#                                                                            #
##############################################################################
F_monkey = vector(0,0,0)
F_banana = vector(0,0,0)

t  = 0                          # Initialize the time variable
dt = 0.001                      # Time step of 0.001 seconds = 1 ms

# Continue until the positions of the Monkey and Banana are within 5 mm of each other
# or the Monkey hits the floor.
while (mag(monkey.pos - banana.pos) > 0.005) and (monkey.pos.y > 0):
    rate(1000)					# Run loop at 1000 time steps per second.
    
    ####################################################################
    #                                                                  #
    # 4. Update the momentum and position of the Monkey                #
    #                                                                  #
    ####################################################################
    
    
    ####################################################################
    #                                                                  #
    # 5. Update the momentum and position of the banana                #
    #                                                                  #
    ####################################################################
    
    
    MonkeyTrajectory.plot(monkey.pos.x, monkey.pos.y)
    bananaTrajectory.plot(banana.pos.x, banana.pos.y)
    
    t = t + dt