Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
1.4 kB
1
Indexable
Never
Web VPython 3.2

scene = canvas(background=color.white)
ground = box (pos=vec(0,-0.02,0), size= vec(3,0.02,0.4), color = color.green)

g = 9.8
m1 = 8.52e-3
rf = 5.8e-2
h0 = 2.03
m4 = 4*m1
rho = 1.045
C = 6.5


f1 = cone(pos=vec(-1,h0,0), axis=vec(0,-1,0), size = vec(0.1,1,0.1), color=color.red, radius=0.1, make_trail=True)

f1.v = vec(0,0,0)
f1.p = f1.v * m1
A = pi * (rf)**2

t = 0
dt = 0.001

f4 = cone(pos=vec(1,h0,0), axis=vec(0,-1,0), size=vec(0.1,1,0.1), color=color.blue, radius=0.1, make_trail=True)
f4.v = vec(0,0,0)
f4.p = f4.v * m4

v_graph = graph(title='Velocity', xtitle= ' t [s] ', ytitle= ' v [m/s] ' )
v_f1_x = gcurve(graph= v_graph, color=color.red)
v_f1_y = gcurve(graph= v_graph, color=color.green)

v_f4_x = gcurve(graph= v_graph, color=color.blue)
v_f4_y = gcurve(graph= v_graph, color=color.cyan)

while f1.pos.y > 0:
    rate(500)
    
    F0= 1/2 * (rho) * (f1.v.mag**2) * (C) * A * -f1.v.hat
    FG = m1 * vec(0,-g,0)
    F = FG + F0
    
    f1.p += (F * dt)
    f1.v = f1.p/m1
    f1.pos += f1.v * dt
    v_f1_y.plot(pos=(t,f1.v.y))
    t+=dt

v1 = f1.v.y
print("time =", t, "velocity =", v1)
t=0
while f4.pos.y > 0:
    rate(500)
    
    F0= 1/2 * (rho) * (f4.v.mag**2) * (C) * A * -f4.v.hat
    Fg = m4 * vec(0,-g,0)
    F = Fg + F0
    
    f4.p += (F * dt)
    f4.v = f4.p/m4
    f4.pos += f4.v * dt

    v_f4_y.plot(pos=(t,f4.v.y))
    
    t+=dt
v4 = f4.v.y
print("time =" ,t,"velocity =" ,v4)
Leave a Comment