diff --git a/week7/README.MD b/week7/README.MD index 6f8dc0f38040d27890a64449d7b67a59f94ca9ef..62e35bb601e1f1d121e8a753bc9a7904dad030e5 100644 --- a/week7/README.MD +++ b/week7/README.MD @@ -13,4 +13,4 @@  -[Talk by a Noita developer on their physics engine](https://www.youtube.com/watch?v=prXuyMCgbTc) +[Talk by a Noita developer on their physics engine](https://www.youtube.com/watch?v=prXuyMCgbTc) \ No newline at end of file diff --git a/week7/img/falling_objects.mp4 b/week7/img/falling_objects.mp4 index 73b145aa6c920407d9ac3ff02e8c19418b9cc125..90ab2842be45e9014d5996a6b3ace15c442c4d56 100644 Binary files a/week7/img/falling_objects.mp4 and b/week7/img/falling_objects.mp4 differ diff --git a/week7/img/rigid_fall.mp4 b/week7/img/rigid_fall.mp4 index ffe600ec9d57dd0c6505e639f3517bed70769d87..015ae7e2f505abc18dd73c68b26e37a9f70579e5 100644 Binary files a/week7/img/rigid_fall.mp4 and b/week7/img/rigid_fall.mp4 differ diff --git a/week7/week7_9_2.py b/week7/week7_9_2.py index e578ced9478d515b653d9cde42de1322272a9284..8ba9556723814beb9df91ee57baf7f0763553426 100644 --- a/week7/week7_9_2.py +++ b/week7/week7_9_2.py @@ -37,12 +37,13 @@ def solve_forces(particles, velocities): # Add some global damping F -= damping_constant_global * velocities F[:, 1] -= gravity # gravity + np.clip(F, -force_threshold, force_threshold, out=F) # clip the force to be within limits of the threshold return F # @jit(nopython=True) def solve_velocities(F, particles, dt): # update the velocity of each particle from V_prev according to the force acting on it - V = dt * F / particle_mass + V = dt * F / particle_mass * 0.95 # some damping here as well # if we contact the ground, reverse the y velocity and dampen it V[:, 1] = np.where((particles[:, 1] < 0), -V[:, 1]*coef_of_restitution, V[:, 1]) # if we cross into the floor, reverse the y velocity and apply a damping factor # apply friction to the ground @@ -77,12 +78,15 @@ height_offset = 8 # 3 for 10x10, 8 for 40x40 # Physical Constants (these alter the particle physics) radius_check = neutral_distance*1.35 -spring_constant = 2000 # 1000 -damping_constant = 18 # 10 -damping_constant_global = 0.25 # air resistance -coef_of_restitution = .1 # 0.5 +spring_constant = 5000 # 1000 +damping_constant = 25 # 10 +damping_constant_global = 0.1 # air resistance +coef_of_restitution = .75 # 0.5 gravity = 1 particle_mass = 0.5 +force_threshold_distance = 0.75 # springs shouldn't get any stronger past this distance +force_threshold = force_threshold_distance*neutral_distance * spring_constant + # Create our triangular mesh of points particles = np.zeros((x_num*y_num, 2)) @@ -142,7 +146,7 @@ def animate(w): velocities = velocities_half + solve_velocities(forces, particles, dt/2) plot.set_offsets(np.c_[particles[:, 0],particles[:, 1]]) -anim = animation.FuncAnimation(fig, animate, frames=int(t_final/dt/2)) +anim = animation.FuncAnimation(fig, animate, frames=int(2*t_final/dt/2)) # plt.show() solve_time = time.time() - time1 @@ -150,8 +154,8 @@ solve_time = time.time() - time1 time2 = time.time() import matplotlib as mpl mpl.rcParams['animation.ffmpeg_path'] = r'C:\ffmpeg_2023_03_30\bin\ffmpeg.exe' -path = r"c://Users/david/Desktop/NMM/week7/figures/animation.mp4" -writervideo = animation.FFMpegWriter(fps=60, extra_args=['-vcodec', 'libx264']) +path = r"c://Users/david/Desktop/NMM/week7/img/animation.mp4" +writervideo = animation.FFMpegWriter(fps=30, extra_args=['-vcodec', 'libx264']) anim.save(path, writer=writervideo, dpi=my_dpi) mp4_time = time.time() - time2