Skip to content

vitorpp0/vectorfieldanimation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

VectorFieldAnimation

Simple class that makes it easy to simulate a Vector Field through an matplotlib animation

Requirements

This class makes use of some Python's modules Numpy and MatPlotLib.

Quick With Predefined Vector Field

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()

Quick Set Up

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()

End

Hope you like it! 😁 Please, consider hiting the star button!!!

About

Simple class that makes it easy to simulate a Vector Field through an matplotlib animation

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages