Untitled
unknown
plain_text
2 years ago
1.5 kB
6
Indexable
Web VPython 3.2
scene = canvas(background = color.black)
ball = sphere(pos = vec(100, -200, 0), mass = 1, v = vec(0, 10, 0), radius = 5, color = color.red, make_trail = True)
ball.p = ball.mass * ball.v
#Velocity graph
v_graph = graph(title = 'Velocity', xtitle = 'time(s)', ytitle = 'm/s')
vx = gcurve(graph= v_graph, color=color.red)
vy = gcurve(graph= v_graph, color=color.blue)
#Work Energy graph
w_graph = graph(title = 'Work Energy', xtitle = 'time(s)', ytitle = 'N m/s')
ball_w = gcurve(graph = w_graph, color = color.green)
ball_KE = gcurve(graph = w_graph, color = color.red)
#Angular momentum graph
L_graph = graph(title = 'Angular Momentum', xtitle = 'time(s)', ytitle = 'kg m^2/s')
ball_L_x = gcurve(graph = L_graph, color = color.red)
ball_L_y = gcurve(graph = L_graph, color = color.blue)
ball_L_z = gcurve(graph = L_graph, color = color.green)
ball.work = 0
ball.K = 1/2 * ball.mass * ball.v.mag2
t = 0
dt = 0.02
myrate = 1000
while ball.pos.x < 200:
rate(myrate)
F = vec(0,0,0)
R = ball.pos
if ball.pos.x < 0 or ball.pos.y > 0:
F = -ball.mass * ball.v.mag2 / R.mag * R.hat
ball.p = ball.p + F*dt
ball.v = ball.p/ball.mass
ball.pos = ball.pos + ball.v * dt
ball.L = cross(R, ball.p)
ball.K = 1/2 * ball.mass * ball.v.mag2
vx.plot(pos=(t, ball.v.x))
vy.plot(pos=(t, ball.v.y))
ball_w.plot(t, ball.work)
ball_KE.plot(t, ball.K)
ball_L_x.plot(t, ball.L.x)
ball_L_y.plot(t, ball.L.y)
ball_L_z.plot(t, ball.L.z)
t += dtEditor is loading...
Leave a Comment