Using matplotlib's ArtistAnimation method The motion of an object performing a parabolic motion is displayed with a trajectory. Here, ** a method of displaying two pictures of the locus part and the moving part of the object in an overlapping manner ** was used. ** It's a simple and easy way for everyone to think, but it may be useful when you want a quick visualization. .. ** **
** It is a vertical throwing problem in the direction of the uniform gravitational field in the direction of $ y $ $ \ theta $. ** **
Assuming that the position of the mass point is $ (x_0, y_0) $ and the magnitude of the initial velocity is $ V_0 $ when the time $ t = 0 $, the mass points $ x (t) $ and $ y (t) at the time $ t $ ) $ Coordinates are as follows. This mass movement draws a parabola.
In this problem, set $ V_0 = 100 $ m / s, $ (x_0, y_0) = (0, 0) $, $ \ theta = \ pi / 4 $ (= 45 degrees) to draw the motion of the mass point. ..
locus.py
"""
Animated parabolic movement with a trajectory
Animation with a locus
"""
import matplotlib.pyplot as plt
%matplotlib nbagg # Jupyter-Add when displaying animation in notebook
from matplotlib.animation import ArtistAnimation #Import methods for creating animations
import numpy as np
fig = plt.figure()
anim = [] #A list for storing the data of the para-para diagram drawn for animation
tt = np.arange(0,15,0.5) #Time setting for drawing: t=0 from 0 to 15.In 5 increments.
x_all=[] #List for storing data at all x positions
y_all=[] #List for storing data at all y positions
#Setting initial conditions
V0 =100 #The magnitude of the initial velocity: 100 m/s
theta=np.pi/4
x0=0 #Initial position: x=0
y0=0 #Initial position: y = 0
g=9.8 #Gravitational constant[m/s^2]
for t in tt:
x= [V0*np.cos(theta)*t+x0] # x(t)Description of
y = [-( g/2)*t**2+V0*np.sin(theta)*t+y0] # y(t)Description of
x_all.append(x[0]) #Stores data every moment of x
y_all.append(y[0]) #Store data every moment of y
#Create two pictures, the mass point at time t and the locus of motion up to time t, and store them in the animation list.
im=plt.plot(x,y,'o', x_all,y_all, '--', color='red',markersize=10, linewidth = 2, aa=True)
anim.append(im)
anim = ArtistAnimation(fig, anim) #Animation creation
#Draw customization
plt.xlabel('X',fontsize=18) #
plt.ylabel('Y',fontsize=18)
plt.xlim(0, 1100)
plt.ylim(-10,300)
plt.hlines([0], 0, 2000, linestyles="-") # y=Draw a line at 0.
fig.show()
anim.save("t.gif", writer='imagemagick') #Animation.Save as gif and create a gif animation file.
An animation of the movement of a mass point when thrown at an initial velocity of 100 m / s in an oblique direction of 45 degrees is displayed with a trajectory.
August 3, 2017: ** Removed mass m in y (t) **. T_Shinaji, thank you for pointing out!
August 10, 2017: Changed from anim.save ("t.gif") to ** anim.save ("t.gif", writer ='imagemagick') **. Thank you to yoddy for pointing out!
For Artist Animation, chez_sugi's Animation with matplotlib I was allowed to refer to.