Visualizations
147 / 500

147 · Algorithms

Tutte Embedding

A hopeless tangle of edges relaxes into a crossing-free drawing, as Tutte proved it must.

Tutte's 1963 theorem says that if you pin the outer face of a 3-connected planar graph to a convex polygon and place every other vertex at the average of its neighbors, no two edges cross and every face is convex. Those averages form a linear system, solved here one damped Jacobi sweep per frame with heavy-ball momentum, so a random scribble with thousands of crossings visibly collapses and unfolds while a live counter checks every pair of edges. The graphs come from a geodesic icosahedron or a 3D convex hull of random points on a sphere: their duals are polyhedral cells, and deleting one vertex gives a triangulated disk. Each face lights up as stained glass once its own edges are clean and it winds the right way, and the same equations are a net of zero-length springs, so dragging the pinned corners makes the interior re-equilibrate.

Try it. Drag the gold outer vertices to reshape the boundary (make it non-convex and crossings can return), or tug an interior vertex and let go. Tangle (Space) scrambles it again and glides a dragged boundary home, and Next graph (N) cycles through four graph families. Puzzle (P) scrambles a smaller graph onto a circle for you to untangle by hand against the clock; Ask Tutte (T) lets the theorem finish from wherever you left it and times it.

  • Tutte barycentric embedding
  • Momentum Jacobi relaxation
  • 3D convex hull and dual graphs
  • Segment intersection counting

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 a demo of Tutte's embedding theorem with JavaScript and the HTML canvas element: a tangled planar graph that untangles itself. 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 resizes with the window. Use a dark background.
- Hard-code a 3-connected planar graph to start with: the dodecahedron (20 vertices, 30 edges) is perfect. Pick one of its pentagons as the outer face.
- Place the five outer vertices on a regular pentagon and pin them. Put every other vertex at a random position inside it, so the drawing is a tangled mess.
- Each frame, move every free vertex part of the way toward the average position of its neighbors (a damped Jacobi step). That is Tutte's barycentric embedding being solved iteratively, and the tangle will settle into a crossing-free drawing.
- Count edge crossings each frame with a segment intersection test (skip pairs that share a vertex), show the count, and draw crossing edges in red.

Once that works, make it beautiful:
- Add momentum (keep a velocity per vertex and decay it each step) so it converges faster and moves like a spring net.
- Let me drag vertices with the pointer. Dragging an outer vertex should reshape the boundary while the interior follows.
- Fill each face with a soft color once the graph is planar, shading faces by how far they are from the outer face.

Explain in short code comments why the averages give a planar drawing. When you're done, tell me how to open it and suggest three directions I could take it next, such as generating bigger graphs from the convex hull of random points on a sphere, a puzzle mode where I untangle it by hand first, or comparing against a force-directed layout.
PreviousIFS EditorSculpt fractals by dragging affine parallelograms while the chaos game redraws them. NextGlyph RasterizerLetters become pixels: exact-area scanline coverage, subpixel RGB and hinting.

Related visualizations

  • Wythoff Kaleidoscope3D One draggable seed in a mirror triangle generates every convex uniform polyhedron.
  • Tessellation MorphMath Drag one edge of an Escher-style creature and every copy reshapes while still tiling.
  • Four-Dimensional PolytopesMath All six regular 4D polytopes, double-rotating through themselves in stereographic 3D.
  • Dissection ProofsMath Proofs without words in cut paper, plus any polygon you draw cut into any other.
  • Penrose PentagridMath Five grids of parallel lines dualize into a living Penrose tiling of stained glass.
  • Slicing Four DimensionsMath A hyperplane sweeps through 4D shapes, leaving glassy 3D cross sections.
  • Girih Star PatternsGenerative art Interlaced Islamic star patterns built live from one angle over a hidden tiling.
  • Tensegrity3D Struts that never touch, floating in a web of cables, found by dynamic relaxation.
  • Marching CubesAlgorithms Watch the classic isosurface algorithm march cell by cell, then zoom out to clay.

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

← More from Emergent Mind Labs