Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View bomb.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
from visual import *
from math import *
 
g=9.80
 
size=0.3
mass=1000
distance=6000
startvel=0
drag=0.5
rho=1.29
area=3.14159*size*size
 
bomb=sphere(pos=vector(-distance/2, distance,0), radius=300*size,color=color.green)
bomb.m=mass
bomb.p=vector(0,0,0)
 
bomb2=sphere(pos=vector(-(distance/2+100*size), distance,0), radius=300*size,color=color.magenta)
bomb2.m=mass
bomb2.p=vector(0,0,0)
 
observer=sphere(pos=vector(+distance/2,0,0), radius=20, color=color.cyan)
target=sphere(pos=vector(-distance/2,0,0), radius=20, color=color.red)
 
Fgrav=bomb.m*g*vector(0,-1,0)
 
t=0
tmax=sqrt(2*distance/g)+12
dt=1
 
print bomb.p
 
 
while bomb.pos.y>0:
rate(10)
if bomb.p.mag>0:
vhat=bomb.p/bomb.p.mag
else:
vhat=vector(0,-1,0)
Fdrag=-0.5*drag*area*rho*bomb.p.mag2*vhat/(bomb.m*bomb.m)
Fnet=Fgrav+Fdrag
 
bomb.p=bomb.p+Fnet*dt
bomb.pos=bomb.pos+dt*bomb.p/bomb.m
r_tar=bomb.pos-target.pos
rel_v_target=dot(bomb.p,r_tar)/r_tar.mag/bomb.m
r_obs=bomb.pos-observer.pos
rel_v_obs=dot(bomb.p,r_obs)/r_obs.mag/bomb.m
 
doppler_tar=-rel_v_target/330
doppler_obs=-rel_v_obs/330
 
bomb2.p=bomb2.p+Fgrav*dt
bomb2.pos=bomb2.pos+dt*bomb2.p/bomb2.m
print t,round(bomb.pos.y,0),round(bomb.p.mag/bomb.m,1),round(doppler_tar,3),round(doppler_obs,3)
 
t=t+dt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.