Untitled
unknown
plain_text
2 years ago
801 B
15
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', ytitle = 'Velocity')
vx = gcurve(graph= v_graph, color=color.red)
vy = gcurve(graph= v_graph, color=color.blue)
t = 0
dt = 0.02
myrate = 500
while ball.pos.x <= 201:
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.mag)**2 / ball.pos.mag * ball.pos.hat
ball.p = ball.p + F*dt
ball.v = ball.p/ball.mass
ball.pos = ball.pos + ball.v * dt
vx.plot(pos=(t, ball.v.x))
vy.plot(pos=(t, ball.v.y))
t += dtEditor is loading...
Leave a Comment