Advertisement
calcpage

CSH2012 FINAL ballistics02.py

Jun 21st, 2013
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.83 KB | None | 0 0
  1. #!/usr/bin/python
  2. #ballistics02.py    MrG     2013.0531
  3. #inspired by http://vpython.erikthompson.com
  4. #horizontal and vertical displacement without air resitance a la Galileo
  5. #position is a vector!
  6. from visual import *
  7.  
  8. scene.width=800
  9. scene.height=600
  10. scene.autoscale=0
  11. scene.range=(100,100,100) #(l,w,h)
  12. scene.center=(0,40,0) #pos vector
  13.  
  14. ball=sphere(pos=(0,102,0),radius=2,color=color.red)
  15. ground=box(pos=(0,-1,0),size=(100,2,10),color=color.green)
  16. building=box(pos=(0,50,0),size=(6,100,6),color=color.blue)
  17.  
  18. g=9.8 #m/s/s
  19. t=0
  20. dt=0.01
  21.  
  22. finished=False
  23. while not finished:
  24.     rate(100) #loop 100 times per sec
  25.     t+=dt
  26.     x=5*t #x(t)=vx0*t+x0
  27.     y=-0.5*g*t**2+0*t+15*t+100 #y(t)=-g*t^2/2+vy0*t+y0
  28.     print "t= " + str(t) + " x= " + str(x) + " y= " + str(y)
  29.     ball.pos=(x,y,0)
  30.     if y-2<0:
  31.         finished=True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement