Visualizations
120 / 500

120 · Machine learning

Manifold Unroll

Isomap and LLE unroll a paper Swiss roll, and tear it when k is too large.

A printed sheet of 784 points is rolled into a Swiss roll, bent into an S-curve or crumpled, and the methods see only the 3D positions. Isomap links each point to its k nearest neighbors, measures geodesic distance along that graph with Dijkstra from 48 farthest-point landmarks, and solves landmark MDS; LLE fits each point as an affine blend of its neighbors and finds the bottom eigenvectors of (I - W)^T(I - W) with a Cholesky factorization and inverse subspace iteration, spread over frames. The answer, aligned by Procrustes, drives the mesh: vertices peel off in order and settle flat on the table. The dark path is the shortest route between two pins along the kNN graph; raise k and red edges short-circuit between layers, the path cheats through them, and the sheet tears into a loop.

Try it. Drag to orbit, click the paper to move the pins A and B, and use the chips to switch Isomap and LLE, change k, pick a shape, unroll or roll up, and toggle the kNN graph. Keys: Space unrolls, M switches method, 1 to 3 pick a shape, + and - change k, G toggles the graph.

  • Isomap
  • Locally linear embedding
  • Dijkstra shortest paths
  • Landmark MDS

View the source · one module, plus a small shared runtime for sizing, the animation loop and input

Build your own

Paste this into Claude Code, Codex or any coding agent to get a simple version running, then take it wherever you like.

Build an interactive Isomap demo that unrolls a Swiss roll, with JavaScript and the HTML canvas element. Put everything in a single index.html file with no libraries or build step, so I can open it directly in a browser.

Start simple:
- Make a canvas that fills the window, stays sharp on high-DPI screens (scale by devicePixelRatio), and has a warm off-white background.
- Generate about 600 points on a Swiss roll: pick t in [1.5 pi, 4.5 pi] and h in [0, 1], and place the point at (t cos t, h * 10, t sin t). Color each point by t with a smooth gradient so you can see the true layout.
- Write a tiny 3D projection: rotate around the vertical axis by a yaw angle, tilt by a pitch angle, apply perspective, and sort points by depth before drawing them as small circles. Drag the mouse to rotate.
- Build the k-nearest-neighbor graph (k = 8) by brute force, then run Dijkstra from every point (or from 50 landmarks) to get geodesic distances along the graph.
- Run classical MDS on those distances: double-center the squared distance matrix and find its top two eigenvectors with power iteration. That gives each point 2D coordinates.
- Press a key to animate every point from its 3D position to its 2D position laid flat, so the roll visibly unrolls.

Once that works, make it beautiful:
- Sample the points on a grid in (t, h) and draw the sheet as shaded quads with simple Lambert lighting, so it looks like paper.
- Draw the shortest path between two points along the graph next to the straight chord through space.
- Add a k slider and highlight graph edges that jump between layers of the roll, then watch the unrolled sheet tear.

Explain the key ideas in short code comments. When you're done, tell me how to open it and suggest three directions I could take it next, such as adding Locally Linear Embedding for comparison, a soft shadow on the floor, or an S-curve and a crumpled sheet as other datasets.
PreviousPalette CyclingA waterfall, harbor rain and an aurora, animated without changing a single pixel. NextMicroswimmersA flagellum, Purcell's three-link swimmer and a scallop that cannot move, in Stokes flow.

Related visualizations

  • Self-Organizing QuiltMachine learning Kohonen maps sew a quilt from fabric dyes and drape a sheet over 3D point clouds.
  • Kernel Trick LiftMachine learning Rings no line can split are lifted into 3D, where an SMO-trained SVM slices them flat.
  • SLE CurvesMath Random fractal curves grown tip first from Loewner's equation, kappa by kappa.
  • Route PlannerAlgorithms Dijkstra, A*, bidirectional search and contraction hierarchies race on a printed atlas.
  • Circle PackingMath Thurston's discrete Riemann map: a live circle packing warps a picture into your blob.
  • Miura FoldMath Miura-ori, Yoshimura and waterbomb sheets fold with exact rigid-origami kinematics.
  • Tutte EmbeddingAlgorithms A hopeless tangle of edges relaxes into a crossing-free drawing, as Tutte proved it must.
  • Viterbi TrellisMachine learning A hidden Markov model catches a dealer swapping in a loaded die, roll by roll.
  • t-SNE ConstellationsMachine learning 2,000 glyph images in 196 dimensions flow into constellations under live t-SNE.

Use ← and → to move between demos. While the canvas has focus, keys go to the demo instead.

← More from Emergent Mind Labs