Advertisement
calcpage

CSH2012 FINAL ballistics04.py

Jun 21st, 2013
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.07 KB | None | 0 0
  1. #!/usr/bin/python
  2. #ballistics04.py    MrG     2013.0531
  3. #inspired by http://vpython.erikthompson.com
  4. #horizontal and vertical displacement like a cannon with a cross wind!
  5. #position is a vector!
  6. #velocity is a vector!
  7. from visual import *
  8.  
  9. scene.width=800
  10. scene.height=600
  11. scene.autoscale=0
  12. scene.range=(100,100,100) #(l,w,h)
  13. scene.center=(50,40,0) #pos vector
  14.  
  15. ball=sphere(pos=(0,2,0),radius=2,color=color.red)
  16. ground=box(pos=(50,-1,0),size=(100,2,10),color=color.green)
  17.  
  18. g=9.8 #m/s/s
  19. vel=40 #m/s
  20. ang=80 #degrees
  21. ang=ang*pi/180 #radians
  22. vx=vel*cos(ang)
  23. vy=vel*sin(ang)
  24. vz=0
  25. vThrow=vector(vx,vy,vz)
  26. vWind=vector(2,1,-5)
  27. vTotal=vThrow+vWind
  28. t=0
  29. dt=0.01
  30.  
  31. finished=False
  32. while not finished:
  33.     rate(100) #loop 100 times per sec
  34.     t+=dt
  35.     x=vTotal.x*t #x(t)=vx0*t+x0
  36.     y=-0.5*g*t**2+0*t+vTotal.y*t+2 #y(t)=-g*t^2/2+vy0*t+y0
  37.     z=vTotal.z*t #z(t)=vz0*t+z0
  38.     print "t= " + str(t) + " x= " + str(x) + " y= " + str(y)
  39.     ball.pos=(x,y,z)
  40.     if y-2<0:
  41.         finished=True
  42.         mylabel=label(pos=(50,60,0),text="seconds in flight: "+str(t),height=10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement