Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from __future__ import division
- from visual import *
- scene.y = 400 # move animation window 400 pixels from top of screen
- from visual.graph import *
- track = box(pos = vector(0.0, -0.05, 0.0), size = (1.0, 0.05, 0.10))
- cart = box(pos = vector(0.0, 0.04, 0.0), size = (0.1, 0.04, 0.06), color = color.green)
- cart.m = 0.80
- cart.v = vector(0.7, 1.0 ,0.0)
- cart.p = cart.m * cart.v
- deltat = 0.005
- t = 0
- #position vs time graph
- gdisplay(xtitle = 'Time', ytitle = 'Position', x = 500, y = 0, width = 600, height = 300)
- posgraph = gcurve(color = color.red) # to make position graph
- #momentum vs time graph
- gdisplay(xtitle = 'Time', ytitle = 'Momentum', x = 500, y = 300, width = 600, height = 300)
- pgraph = gcurve(color = color.green) # to make momentum graph
- #net force vs time graph
- gdisplay(xtitle = 'Time', ytitle = 'Net Force', x = 500, y = 600, width = 600, height = 300)
- Fgraph = gcurve(color = color.blue) # to make net force graph
- while t < 5.0:
- rate(100)
- Fnet = vector(-0.4, -7.84, 0.0)
- cart.p = cart.p + Fnet * deltat
- print "t = ", t, "cart.p = ", cart.p, "cart.pos = ", cart.pos
- cart.pos = cart.pos + (cart.p / cart.m) * deltat
- t = t + deltat
- if (cart.pos.y <= 0) & (cart.pos.x >= -.5):
- cart.p.y = abs(cart.p.y) # make the cart move upwards
- posgraph.plot(pos = (t, cart.pos.x))
- pgraph.plot(pos = (t, cart.p.x))
- Fgraph.plot(pos = (t, Fnet.x))
Advertisement
Add Comment
Please, Sign In to add comment