• API
• FAQ
• Tools
• Trends
• Archive
daily pastebin goal
7%
SHARE
TWEET

# CSH2012 FINAL ballistics03.py

calcpage Jun 21st, 2013 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #!/usr/bin/python
2. #ballistics03.py    MrG     2013.0531
3. #inspired by http://vpython.erikthompson.com
4. #horizontal and vertical displacement given velocity vector from the ground like a cannon!
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=(50,40,0) #pos vector
13.
15. ground=box(pos=(50,-1,0),size=(100,2,10),color=color.green)
16.
17. g=9.8 #m/s/s
18. vel=40 #m/s
19. ang=80 #degrees
21. vx=vel*cos(ang)
22. vy=vel*sin(ang)
23. t=0
24. dt=0.01
25.
26. finished=False
27. while not finished:
28.     rate(100) #loop 100 times per sec
29.     t+=dt
30.     x=vx*t #x(t)=vx0*t+x0
31.     y=-0.5*g*t**2+0*t+vy*t+2 #y(t)=-g*t^2/2+vy0*t+y0
32.     print "t= " + str(t) + " x= " + str(x) + " y= " + str(y)
33.     ball.pos=(x,y,0)
34.     if y-2<0:
35.         finished=True
RAW Paste Data
Top