Skip to content

An interactive simulation that allows users to create external vectors within an existing vector field and observe how their gradient, divergence, and curl evolve over time. This tool provides a visual way to explore the dynamics of vector fields and deepen understanding of key concepts in vector calculus, such as field behavior and fluid flow

Notifications You must be signed in to change notification settings

AakaashfromIndia/VectorFieldSimulation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

Interactive Vector Field Simulation

image

This project is an interactive computational tool designed to help users visualize, manipulate, and analyze two-dimensional vector fields. At its core, it combines mathematical concepts from vector calculus with intuitive graphical interaction, making abstract field properties accessible and visually engaging.

A vector field in two dimensions assigns a vector (with both magnitude and direction) to every point in a plane. Mathematically, such a field is often written as:

image

where U(x,y) and V(x,y) are the field's components in the x and y directions, respectively.

Initial Field Construction

The project begins by letting the user define a uniform vector field. This means every point in the grid has the same vector, determined by user-supplied constants a and b. A key feature is the ability to draw arrows directly onto the field. Each arrow is mathematically interpreted as a localized perturbation—an influence that modifies the field in its vicinity. When a user draws an arrow from (x0,y0) to (x1,y1), it represents a vector influence with direction and strength proportional to the arrow's length and orientation.

The effect of each arrow is not limited to a single point; instead, it decays with distance from its origin, affecting the entire field but most strongly near where it was drawn. This is modeled as:

image

The resultant field is the sum of the initial uniform field and the cumulative effects of all user-drawn arrows:

Field Analysis: Gradient, Divergence, and Curl

The tool offers further insight by enabling overlays of key vector calculus properties:

  • Gradient Magnitude: Measures how rapidly the field changes in space. It is computed as the root of the sum of squares of all spatial derivatives of the field components.
  • Divergence: Indicates the presence of sources (where field lines spread out) or sinks (where they converge)
  • Curl: Measures the tendency of the field to induce rotation around a point:

These properties are computed numerically using finite differences and visualized as color overlays, making abstract mathematical concepts tangible.

Example: image

Installation

  1. Clone the repository:

    git clone https://github.com/yourusername/vector-field-visualizer.git
    cd vector-field-visualizer
  2. Install dependencies:

    pip install numpy matplotlib scipy

Usage

  1. Run the script:

    python vector_field_visualizer.py
  2. Set Initial Field:

    • Enter the x and y components (a, b) for the initial field when prompted.
  3. Draw Arrows:

    • Left panel: Click and drag to draw arrows (red) representing additional vector influences.
  4. Calculate Resultant:

    • Click the "Calculate Resultant" button to update the field with your drawn arrows.
  5. Analyze the Field:

    • Use the right panel buttons to:
      • Display only field: Show the resultant field.
      • Overlay gradient: Visualize the field's gradient magnitude.
      • Overlay divergence: Visualize the field's divergence.
      • Overlay curl: Visualize the field's curl.

Controls & Buttons

Button Function
Calculate Resultant Updates the field with user-drawn arrows
Display only field Shows only the resultant vector field
Overlay gradient Adds a gradient magnitude heatmap
Overlay divergence Adds a divergence heatmap
Overlay curl Adds a curl heatmap

Requirements

  • Python 3.7+
  • numpy
  • matplotlib
  • scipy

About

An interactive simulation that allows users to create external vectors within an existing vector field and observe how their gradient, divergence, and curl evolve over time. This tool provides a visual way to explore the dynamics of vector fields and deepen understanding of key concepts in vector calculus, such as field behavior and fluid flow

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages