concept-collection / hitandrun-interactive
hitandrun-interactive / README.md
4.5 KBPreviewCodeBlameHistoryRaw

Interactive hit-and-run sampling#

Runs in the browser via numbl — no install.

🎛 Just the figure →#

The figure-only view runs the sampler and drops you straight into the interactive figure (it shows the run's output first, then the figure). The full developer view — file tree, editable code, console — is below.

Open hitandrun_demo.m and click Run#

A random 2D region is generated and N points are drawn uniformly from it by hit-and-run: from the current point, pick a random direction, take the chord where that line crosses the region, and jump to a uniform point on it. Repeat. The figure shows the region and the samples. The region is convex by default, but you can switch to a non-convex dumbbell — two convex bulbs joined by a narrow tube — where a single line can enter and leave the region more than once.

Controls:

How it works#

The script and figure talk both ways: the script sends the region + samples via uihtml(..., 'Data', ...), and the controls call back with sendToMATLAB('resample' | 'newRegion', ...) (each carrying whether the region is convex and, for non-convex, the local sampling mode), which re-runs the sampler and returns new points via sendEventToHTMLSource. The script is stateless — the figure owns the region and passes it back with each request.

Convex vs. non-convex#

hitandrun_sampler.m picks the sampler by region type:

Deploy#

Pushing to main builds the app and publishes the project to GitHub Pages via the deploy workflow.