Visualizations
319 / 500

319 · Math

Four-Dimensional Polytopes

All six regular 4D polytopes, double-rotating through themselves in stereographic 3D.

The six regular convex polytopes of four dimensions, from the 5-cell and tesseract to the 120-cell's 600 vertices and 1,200 edges, are built from coordinates on the unit 3-sphere (the 600-cell from the 120 unit icosians, the 120-cell from the centers of its 600 tetrahedra), with cells found from the dual polytope. A 4x4 rotation turns them through the six planes of 4D space; the default is an isoclinic double rotation, equal turns in XY and ZW, which has no fixed axis, so cells stream out of the center, swell past you and return from the far side. Edges are great-circle arcs stereographically projected into circular arcs, thickened by the projection's scale factor and colored by 4D depth, then drawn as depth-sorted shaded tubes.

Try it. Drag to turn through the XW and YW planes (Shift or right-drag for ZW), scroll or press + and - to move the projection point, and tap a cell to light up its ring of cells around a great circle (tap again for another ring). Space pauses the double rotation, 1 to 6 pick a polytope.

  • Stereographic projection
  • Isoclinic rotation
  • Dual polytopes
  • Painter's algorithm tubes

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 viewer for four-dimensional polytopes 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 resizes with the window. Use a deep blue-black background.
- Build a tesseract: its 16 vertices are (+-1, +-1, +-1, +-1) / 2, and two vertices share an edge when they differ in exactly one coordinate.
- Keep a 4x4 rotation matrix. Each frame, rotate it a little in the XY plane and by the same amount in the ZW plane at once (an isoclinic double rotation).
- Project each rotated 4D point to 3D with (x, y, z) / (s - w) for s around 1.4, then to the screen with ordinary perspective, and draw every edge as a line.

Once that works, make it beautiful:
- The vertices lie on the unit 3-sphere, so draw each edge as a great-circle arc: interpolate between its endpoints with slerp in 4D and project 10 points along the way. The edges become curved arcs.
- Draw the edges as thick strokes whose width grows with 1 / (s - w) and whose color follows w, sorted far to near so the near ones overlap the far ones.
- Let the user drag to rotate in the XW and YW planes and scroll to change s.
- Add the 16-cell (permutations of (+-1, 0, 0, 0)) and the 24-cell (permutations of (+-1, +-1, 0, 0), normalized) with buttons to switch.

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 building the 600-cell from the 120 unit icosians, turning edges into shaded tubes, or highlighting a ring of cells that wraps around a great circle.
PreviousKaleidoscopeDraw once, and twelve mirrored strokes bloom into a mandala. NextBait Ball1,400 silver sardines mill, stream and pack into a bait ball as dolphins close in.

Related visualizations

  • Slicing Four DimensionsMath A hyperplane sweeps through 4D shapes, leaving glassy 3D cross sections.
  • Hopf Fibration3D The 3-sphere as linked circles, projected into nested tori of pastel rings.
  • Wythoff Kaleidoscope3D One draggable seed in a mirror triangle generates every convex uniform polyhedron.
  • Tutte EmbeddingAlgorithms A hopeless tangle of edges relaxes into a crossing-free drawing, as Tutte proved it must.
  • Penrose PentagridMath Five grids of parallel lines dualize into a living Penrose tiling of stained glass.
  • Map ProjectionsMath One procedural planet morphing through a dozen map projections, Tissot ellipses and all.
  • Catalan BijectionsMath One Catalan object drawn five ways at once, linked piece by piece as it morphs.
  • Hyperbolic TilingMath An endless koi garden of {p,q} ponds tiling the Poincare disk, with fish circling.
  • Circle PackingMath Thurston's discrete Riemann map: a live circle packing warps a picture into your blob.

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

← More from Emergent Mind Labs