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:
where U(x,y) and V(x,y) are the field's components in the x and y directions, respectively.
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:
The resultant field is the sum of the initial uniform field and the cumulative effects of all user-drawn arrows:
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.
-
Clone the repository:
git clone https://github.com/yourusername/vector-field-visualizer.git cd vector-field-visualizer
-
Install dependencies:
pip install numpy matplotlib scipy
-
Run the script:
python vector_field_visualizer.py
-
Set Initial Field:
- Enter the x and y components (a, b) for the initial field when prompted.
-
Draw Arrows:
- Left panel: Click and drag to draw arrows (red) representing additional vector influences.
-
Calculate Resultant:
- Click the "Calculate Resultant" button to update the field with your drawn arrows.
-
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.
- Use the right panel buttons to:
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 |
- Python 3.7+
- numpy
- matplotlib
- scipy