Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
1.6 kB
3
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.779
m1 = 8.52e-3
rf = 5.8e-2
h0 = 2.03
m4 = 4 * m1
rho = 1.045
C_D = 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 = m1 * f1.v
A = pi * (rf)**2

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 = m4 * f4.v

v_graph = graph(title='Ball Speed', xtitle= 't', ytitle= 'v(t)')
v_f1_x = gcurve(graph= v_graph, color=color.red)
v_f1_y = gcurve(graph= v_graph, color=color.blue)

v_f4_x = gcurve(graph= v_graph, color=color.green)
v_f4_y = gcurve(graph= v_graph, color=color.orange)

t = 0
dt = 0.001
myrate = 500

scene.waitfor('click')

while f1.pos.y > 0:
    rate(myrate)
    
    F_D1 = 1/2 * rho * A * C_D * (f1.v.mag**2) * -f1.v.hat
    Fg = m1 * vec(0, g, 0)
    F = F_D1 + Fg
    
    f1.p = f1.p + F * dt
    f1.v = f1.p/m1
    f1.pos = 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

scene.waitfor('click')

while f4.pos.y > 0:
    rate(500)
    
    F_D4 = 1/2 * rho * A * C_D * (f4.v.mag**2) * -f4.v.hat
    Fg = m4 * vec(0, g, 0)
    F = F_D4 + Fg
    
    f4.p = f4.p + F * dt
    f4.v = f4.p/m4
    f4.pos = 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