from __future__ import division
from visual import *
from visual.graph import *
scene.y=400
# Create objects: ground, package, and plane
# Ground is at y=0
# Package initial height is 1000 m
# Package size is enlarged for viewing. For calculations, consider it to be 2 m diameter
# For visibility, plane's height is 1050 m, slightly above the package
ground = box(pos=vector(0,0,0), length = 2000, height = 10, width = 1000, color=color.green)
package = sphere(pos=vector(-1000, 1000, 0), radius = 25, color=color.yellow)
plane = box(pos=vector(-1000,1050,0), length = 100, height = 50, width = 50, color=color.red)
# Turn off autoscaling
scene.autoscale = 0
# Create trails for plane and package
planetrail = curve(color=plane.color)
packagetrail = curve(color=package.color)
packagetrail_drop = curve(color=color.cyan)
# Constants
package.m = 100 # mass of package in kg
g = 9.81 # strength of gravitational field near Earth's surface in N/kg
D = 1.3 # Density of air at sea level in kg/m**3
C = 0.175/2 # Approx. drag coeff. for this scenario
A = pi*1**2 # Cross sectional area: 2 m diameter package.
# Initial velocity and momentum of the plane and package
plane.v = vector(90,0,0) #(About 200 mph)
package.v = plane.v # Package has same initial velocity as plane
package.p = package.m*package.v # Initial momentum of package
# Initialize time, define time step
t=0
deltat = 0.02
# Two while loops in this program. The first lasts for five (simulated) seconds,
# and models the plane moving at a constant velocity with the package still
# attached to the plane.
while t < 5:
rate(100)
# update positions
plane.pos = plane.pos + plane.v*deltat
package.pos = package.pos + package.v*deltat
# update trails
planetrail.append(pos=plane.pos)
packagetrail.append(pos=package.pos)
# update time
t=t+deltat
# Change the color of the package to indicate it has been dropped
package.color = color.cyan
# Re-initialize time to zero--t=0 is when package is dropped
t=0
# The second while loop, below, models the motion of the package (and the plane)
# after the package is dropped. Motion coninues until the package's height reaches
# zero.
# MODIFY THE CODE IN THIS LOOP according to the instructions in the lab handout.
while package.pos.y > 0:
rate(100)
# Calculate the net force on the package
# Update the momentum of the package
# Update the positions of the package and the plane
# Update the trails of the package and the plane
# Update time
print "Package hit the ground"
print "time=", t, "s"
# In addition to time, print the final values of the following quantities:
# magnitude of package velocity
# x-component of package velocity
# y-component of package velocity
# x-position of plane
# x-position of package