MCPcopy Create free account
hub / github.com/Apress/python-for-matlab-development / timestep

Function timestep

code/plots/bouncing_ball.py:45–59  ·  view source on GitHub ↗
(pos,vel)

Source from the content-addressed store, hash-verified

43point, trace = None, None
44
45def timestep(pos,vel):
46 new_pos = copy(pos)
47 new_vel = copy(vel)
48 new_vel[1] += -9.8*dt
49 new_vel *= damping
50 new_pos[0] += new_vel[0]*dt
51 new_pos[1] += new_vel[1]*dt
52 bowl_y = A*new_pos[0]**2
53 if new_pos[1] < bowl_y:
54 # hit the bowl, bounce back
55 normal = np.array([-2*A*new_pos[0],1])
56 normal /= np.linalg.norm(normal)
57 new_vel += -2*new_vel.dot(normal)*normal
58 new_pos[1] = bowl_y
59 return new_pos, new_vel
60
61def run_simulation():
62 nX = 21

Callers 1

run_simulationFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected