from modsim import *
params = Params(
x = 0,
y = 1,
angle = 45,
speed = 40,
mass = 145e-3,
diameter = 73e-3,
C_d = 0.33,
rho = 1.2,
g = 9.8,
t_end = 10,
)
from modsim import *
from numpy import pi, deg2rad
def make_system(params):
theta = deg2rad(params.angle)
vx, vy = pol2cart(theta, params.speed)
init = State(x=params.x, y=params.y, vx=vx, vy=vy)
area = pi * (params.diameter/2)**2
return System(params,
init = init,
area = area)
from modsim import *
def drag_force(V, system):
rho, C_d, area = system.rho, system.C_d, system.area
mag = rho * vector_mag(V)**2 * C_d * area / 2
direction = -vector_hat(V)
f_drag = mag * direction
return f_drag
from modsim import *
def slope_func(t, state, system):
x, y, vx, vy = state
mass, g = system.mass, system.g
V = Vector(vx, vy)
a_drag = drag_force(V, system) / mass
a_grav = g * Vector(0, -1)
A = a_grav + a_drag
return V.x, V.y, A.x, A.y
from modsim import *
def event_func(t, state, system):
x, y, vx, vy = state
return y