#This is a shell program implementing the basic impulse-momentum analysis #setup from __future__ import division from visual import * #constants #create objects & initial conditions #OBJECTS: movingblob = sphere(pos = vector(0,0,0), radius = 5, color=color.white) #movingblob is a sphere of radius 5 positioned at the origin #INITIAL CONDITIONS referencefloor = box(pos = vector(0,-.05,0), size = vector(600,.1,1),color=color.red) #referencefloor creates a horizontal line for use as reference for the moving blob movingblob.mass = 15 movingblob.velocity = vector(30,40,0) movingblob.p = movingblob.mass * movingblob.velocity #This assignes a starting mass, velocity, and momentum (p) to # the blob. Note that this blob is moving diagonally # (theta = 53 degrees, magnitude = 50 units) netforce = vector(0,-150,0) fmag = sqrt(netforce.x**2 + netforce.y**2 + netforce.z**2) fhat = netforce/fmag #netforce is the net force acting on the blob. # fmag is the magnitude of this force, fhat is a unit vector # in the direction of this net force. t = 0 dt = 0.01 #t is the initial time, dt is the size of the time step. #calculations while t<100: #loop until 100 seconds have passed rate(100) #This limits program to 100 loops per second, each of which # takes 0.01 s (dt), so it approximates real time movingblob.pos = movingblob.pos + (movingblob.p/movingblob.mass)*dt #current position = prev. position + velocity * deltat movingblob.p = movingblob.p + netforce*dt #current momentum = prev. momentum + change in momentum # (change in momentum = force * deltat) t = t + dt #keep track of the current time