Interactive 2D vector-field explorer for building intuition for divergence and curl. AI Generated finetuned for the visualisation and not code quality.
divergence_curl.mov
This repository is a small C + Raylib application that lets you pan around synthetic flow fields, flip between divergence and curl, drop probes into the scene, and inspect the finite-difference stencil used to estimate each quantity. It also includes a second explainer page focused on the sign convention in the curl formula.
- Renders a live 2D vector field with arrow glyphs and animated particles
- Colors the field by the currently selected derived quantity:
div Forcurl F - Shows a hover inspector with the local vector value and numerical estimate
- Draws a finite-difference stencil and step-by-step derivative breakdown at the cursor
- Lets you place persistent probes to compare multiple locations
- Includes several presets built from sources, sinks, vortices, and base flows
- Includes a second page that visually explains why
curl ~= dFy/dx - dFx/dy
The field page cycles through five built-in scenes:
Mixed Playground: waves, sources, sinks, and vortices combinedSource And Sink: strong positive and negative divergenceCounter Rotations: mostly rotational structure with strong curlExpansion Vs Spin: a side-by-side contrast between spreading and spinningShear With Eddy: a background shear flow with a localized vortex
q: quit1: open the interactive field page2: open the curl-sign explainer pagevortab: toggle between divergence and curlp: cycle to the next field presetspace: pause or resume particle advection on the field pager: reset camera, probes, particles, and animation time
left drag: pan the cameramouse wheel: zoom toward the cursorleft click: place a probe at the clicked world positionhover: inspect the local vector, numerical quantity, and derivative stencil
raylibpkg-config- a C compiler such as
ccorclang
make
make runTo remove the built binary:
make clean- Arrow field: the base vector field
F(x, y) - Heatmap: the numerically sampled divergence or curl at each grid cell
- Particles: flow direction and speed over time
- Hover stencil: the local centered-difference samples used for the derivative estimate
- Probe labels: persistent sampled locations for comparing values across the scene
- The app window is resizable.
- The numerical estimates are centered finite differences sampled around the cursor or probe position.
- Page
2is not another simulation scene; it is a visual explainer for the curl minus sign.