Skip to content

@orzelc /bomb.py
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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.