Skip to content

jamylak/divergence02

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

divergence02

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.

What This Repo Does

  • Renders a live 2D vector field with arrow glyphs and animated particles
  • Colors the field by the currently selected derived quantity: div F or curl 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

Presets

The field page cycles through five built-in scenes:

  • Mixed Playground: waves, sources, sinks, and vortices combined
  • Source And Sink: strong positive and negative divergence
  • Counter Rotations: mostly rotational structure with strong curl
  • Expansion Vs Spin: a side-by-side contrast between spreading and spinning
  • Shear With Eddy: a background shear flow with a localized vortex

Controls

Global

  • q: quit
  • 1: open the interactive field page
  • 2: open the curl-sign explainer page
  • v or tab: toggle between divergence and curl
  • p: cycle to the next field preset
  • space: pause or resume particle advection on the field page
  • r: reset camera, probes, particles, and animation time

Field Page

  • left drag: pan the camera
  • mouse wheel: zoom toward the cursor
  • left click: place a probe at the clicked world position
  • hover: inspect the local vector, numerical quantity, and derivative stencil

Build

Dependencies

  • raylib
  • pkg-config
  • a C compiler such as cc or clang

Commands

make
make run

To remove the built binary:

make clean

How To Read The Visualization

  • 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

Notes

  • The app window is resizable.
  • The numerical estimates are centered finite differences sampled around the cursor or probe position.
  • Page 2 is not another simulation scene; it is a visual explainer for the curl minus sign.

About

Divergence / Curl

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors