d2jsp
Log InRegister
d2jsp Forums > Off-Topic > General Chat > Homework Help > My Program For Momentum And Gravity > Vpython - Check It Out!
Add Reply New Topic New Poll
Member
Posts: 15,854
Joined: Apr 23 2013
Gold: Locked
Trader: Scammer
Feb 21 2019 10:30pm
# Lab 04 - Momentum and Gravity

# Model the motion of a basketball that is tossed vertically upward & you can
# simulate the ball bouncing by changing init velocity vector to (-y) line 21

students = 'Sunzuu likes the D'
scene = canvas(title = 'Week 4: Momentum & Gravity ' + students,
width = 800, height = 600, background = color.white)


floor = box(length=4, width=1, height=0.1, pos=vector(0, -0.05, 0), color=color.black)


ball = sphere(texture="https://i.imgur.com/gpgs0IL.jpg", emissive=True)
ball.radius = 0.12 # The radius of the basketball in meters
ball.pos = vector(0, 1.5, 0) # The initial position of the ball in m
ball.m = .6063 # The mass of the basketball in kg
ball.v = vector(0,1,0) # The initial velocity of the basketball in m/s
ball.p = ball.m * ball.v # The initial momentum of the basketball in kg m/s


scene.center = ball.pos



PositionGraph = graph(title = 'Position vs Time: ', width = 800, height = 300,
xtitle = 'Time (s)', ytitle='Position (m)', fast = False)
PositionVsTime = gcurve(color = color.blue, width = 2, label = 'Position, y')


MomentumGraph = graph(title = 'Momentum vs Time: ', width = 800, height = 300,
xtitle = 'Time (s)', ytitle = 'Momentum (kg m/s)', fast = False)
MomentumVsTime = gcurve(color = color.red, width = 2, label = 'Momentum, p_y')


g = 9.80
dt = 0.001
t = 0


while(t<5):
rate(1000)

#Part B C Input of updates in while loop as follows:

Fgrav=vector(0,-ball.m*g,0) #
Fnet=Fgrav
pfinal= ball.p + Fnet * dt

ball.pos=ball.pos+(ball.p/ball.m)*dt



if (ball.pos.y < ball.radius):
ball.p.y = abs(ball.p.y)*1
#Part D "Coefficient of Restitution"

t = t + dt


PositionVsTime.plot(t, ball.pos.y)
MomentumVsTime.plot(t, ball.p.y)
Member
Posts: 15,854
Joined: Apr 23 2013
Gold: Locked
Trader: Scammer
Feb 21 2019 10:34pm
Feel free to add it to your own glowscript to see how the basketball ( my basketball at home weighed exactly 606.3 g ( .6063 kg) )
moves vertically ( simulating being tossed in a vertical direction ) or
change line 21 I think --- initial input velocity vector ( x ((( y ))) z ) change y to a negative and the graphics will show the ball falling at
9.8g constant to the ground and bouncing back up.

Position vs. time and momentum vs. time graphs are pretty accurate. You will notice the changes on the graph during the bounce.

Scroll in to see my texture added to the basketball also!!!

Pretty cool!!!!!
Go Back To Homework Help Topic List
Add Reply New Topic New Poll