Simple class that makes it easy to simulate a Vector Field through an matplotlib animation
This class makes use of some Python's modules Numpy and MatPlotLib.
This run the predefined vector field.
import sys
path = r"Directory/Path/Where/The/vectorfieldanimation.py/Is"
sys.path.insert(1,path)
# Importing the VectorFieldAnimation.py
import vectorfieldanimation as vfa
# Instancianting Our VectorFieldAnimation Object
vfaObject = vfa.VectorFieldAnimation()
# Running the simulation and animation
vfaObject.animate()Now let's set our Vector Field.
import sys
path = r"Directory/Path/Where/The/VectorFieldAnimation.py/Is"
sys.path.insert(1,path)
# Importing the VectorFieldAnimation.py
import vectorfieldanimation as vfa
# Setting Up Our Vector Field
import numpy as np # Because we always need it
# Sets Our 3D Space and the vectors tails
x_axis = np.arange(-2,2,0.5)
y_axis = np.arange(-2,2,0.5)
z_axis = np.arange(-2,2,0.5)
spaceMesh = [x_axis, y_axis, z_axis]
# Setting the Vector Components Functions in terms of x,y,z and time
# Remember, x,y and z are Numpy arrays, so use Numpy functions!!
x_component = "4*time*x"
y_component = "-2*(time**2)*y"
z_component = "4*np.multiply(x,z)"
componentsFunctions = [x_component, y_component, z_component]
# Instancianting Our VectorFieldAnimation Object
vfaObject = vfa.VectorFieldAnimation(space=spaceMesh, vectorComponents=componentsFunctions, length=0.3, animationDuration=2)
# animationDuration must be in seconds and length is the vectors lengths
# Running the simulation and animation
vfaObject.animate()Hope you like it! 😁 Please, consider hiting the star button!!!