%matplotlib inline from IPython.html.widgets import interact, interactive from IPython.display import clear_output, display, HTML import numpy as np from itertools import count, takewhile from matplotlib import pyplot as plt from matplotlib.colors import cnames from matplotlib import animation plt.rcParams['axes.color_cycle']=['k'] plt.rcParams['figure.figsize']= (18.0, 12.0) g = 9.81 v0_max = 10.0 y_max = v0_max ** 2 / (2 * g) x_max = v0_max ** 2 / g def init_plt(): ax = plt.gca() ax.set_aspect('equal') ax.set_xlim(-x_max - 0.1, x_max + 0.1) ax.set_ylim(0, y_max + 0.1) plt.xlabel('x (m)') plt.ylabel('y (m)') plt.grid(True) def free_fall_coords(v0, alpha): alpha = np.deg2rad(alpha) T_L = 2 * v0 * np.sin(alpha) / g t = np.linspace(0.0, T_L, 30) x = v0 * np.cos(alpha) * t y = v0 * np.sin(alpha) * t - g * t * t / 2 return x, y def free_fall(v0 = 7.0, alpha = 60): x, y = free_fall_coords(v0, alpha) init_plt() plt.plot(x, y) free_fall(10) w = interactive(free_fall, v0=(0.,v0_max,v0_max/10), alpha=(0,180,5)) display(w) def vertex_coords(v0, alpha): y_max = v0 ** 2 * np.sin(alpha) ** 2 / (2*g) x_max = v0 ** 2 * np.sin(2 * alpha) / (2*g) return x_max, y_max def free_fall_fan(v0 = 7.0): init_plt() for alpha in range(0, 180, 5): x, y = free_fall_coords(v0, alpha) plt.plot(x, y, lw=0.3) alpha = np.linspace(0, np.pi, 180/5, endpoint=False) x_max, y_max = vertex_coords(v0, alpha) plt.plot(x_max, y_max, 'cp') free_fall_fan(10) w = interactive(free_fall_fan, v0=(0.,v0_max,v0_max/10)) display(w) def free_fall_wedge(alpha = 60): init_plt() v0 = np.linspace(0.0, 10.0, 10.0/0.5 + 1) for v in v0: x, y = free_fall_coords(v, alpha) plt.plot(x, y, lw=0.3) x_max, y_max = vertex_coords(v0, np.deg2rad(alpha)) plt.plot(x_max, y_max, 'cp') free_fall_wedge() w = interactive(free_fall_wedge, alpha=(0,180,5)) display(w) def free_fall_coords2(v0, alpha, y_ground): T_land = max(takewhile(lambda t: v0 * np.sin(alpha) * t - g*t*t / 2 >= y_ground, count(0, 0.05))) t = np.linspace(0.0, T_land, 30) x = v0 * np.cos(alpha) * t y = v0 * np.sin(alpha) * t - g * t * t / 2 return x, y def focus_coords(v0, alpha): x = v0 ** 2 * np.sin(2 * alpha) / (2*g) y = -v0 ** 2 * np.cos(2 * alpha) / (2*g) return x, y def directrix_coords(v0, alpha): x = v0 ** 2 * np.sin(2 * alpha) / (2*g) y = v0 ** 2 / (2*g) - 0*alpha return x, y def focus_pocus(v0 = 7.0): init_plt() ax = plt.gca() ax.set_ylim(-(y_max + 0.3), y_max + 0.3) alpha = np.linspace(0, np.pi, 180/5, endpoint=False) for a in alpha: x, y = free_fall_coords2(v0, a, -5) plt.plot(x, y, lw=0.3) x, y = focus_coords(v0, alpha) plt.plot(x, y, 'cp') x, y = directrix_coords(v0, alpha) plt.plot(x, y, 'rx') focus_pocus(10) def free_fall_coords3(v0, alpha, T): t = np.arange(0, T+0.05, 0.05) x = v0 * np.cos(alpha) * t y = v0 * np.sin(alpha) * t - g * t * t / 2 return x, y def free_fall_star(v0 = 3.0, t = 3.0): init_plt() ax = plt.gca() ax.set_ylim(-6, 0.7) ax.set_xlim(-3, 3) alpha = np.linspace(0, 2*np.pi, 360/5, endpoint=False) u = [] v = [] for a in alpha: x, y = free_fall_coords3(v0, a, t) u.append(x[-1]) v.append(y[-1]) plt.plot(x, y, lw=0.3) plt.plot(u, v, 'cp') free_fall_star(3.0, 0.7) w = interactive(free_fall_star, v0=(2.0,4.0,0.5), t=(0.,1.0,0.1)) display(w) y[-1] np.append(a, [1,2,3]) %%latex $\frac{v_{0}}{g} \sin(\alpha)$