Visualizations
034 / 500

034 · Physics

Rotary Engine

A cutaway Wankel engine with exact rotor geometry and a live PV diagram.

The housing bore is an epitrochoid, and the rotor orbits the shaft at the eccentricity while turning at a third of its speed, held in step by a 30-tooth ring gear rolling on a fixed 20-tooth pinion, so each apex rides exactly on the bore. The rotor flanks are computed, not drawn: the bore is swept through a revolution in the rotor's frame and the closest it comes in every direction is the inner envelope, which becomes the flank after a running clearance and a combustion recess are cut. Each chamber's volume is the area between bore and flank, and its gas is compressed adiabatically, refilled or emptied through the ports, and burned with a Wiebe function after the spark. The virtual work of all three chambers drives a flywheel against friction, so the speed, the lumpy idle and the pressure-volume loop all come out of the model.

Try it. Drag the throttle lever, or press and hold anywhere to floor it and watch the combustion flashes speed up. Arrow keys move the lever and Space blips the throttle. Left alone, it idles, climbs to full power and blips.

  • Epitrochoid and envelope geometry
  • Shoelace chamber volumes
  • Adiabatic gas cycle with Wiebe burn

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 animated cutaway of a Wankel rotary engine 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 full-window canvas with a dark background that stays sharp on high-DPI screens (scale by devicePixelRatio).
- Draw the housing bore as the epitrochoid x = e cos 3a + R cos a, y = e sin 3a + R sin a, with R = 1 and e = 1/7, scaled to fit the screen.
- Animate the shaft angle b. The rotor centre sits at e(cos b, sin b) and the rotor turns at b / 3. Its three apexes are the centre plus R(cos(b/3 + 2 pi k/3), sin(b/3 + 2 pi k/3)); check that they land exactly on the bore.
- Draw the rotor as three gently bulging arcs between the apexes (a little inside the bore) and fill each of the three chambers between rotor and bore with its own colour.

Once that works, make it an engine:
- Compute each chamber's area with the shoelace formula; each should expand and shrink twice per rotor turn.
- Add an intake and an exhaust port near one waist of the bore and a spark plug at the other. Give each chamber a pressure: when no port is open, keep p times V to the power 1.35 constant; when a port is open, ease p toward the port's pressure; when the chamber passes the plug, add a burst of pressure.
- Colour chambers by stage (blue intake, violet compression, orange power, grey exhaust) and draw a live pressure-volume loop for one chamber on log-log axes.

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 computing the true rotor flank as the inner envelope of the bore, a throttle that changes intake pressure and engine speed, or drawing the 3:2 ring gear and pinion that keep the rotor in phase.
PreviousFloral OrnamentScrolls, acanthus leaves and flowers grow to fill any frame, like an engraver's panel. NextHuffman GardenLetter frequencies sprout into a Huffman tree drawn as a botanical plate.

Related visualizations

  • Rotor Cipher MachineRetro A brass and walnut rotor machine whose current you can follow through every wire.
  • Rose EngineGenerative art A simulated rose engine lathe cuts banknote-fine guilloche, one pass at a time.
  • Gear Train WorkshopPhysics A blueprint bench where involute gears snap into mesh, drive clocks and jam.
  • Watch MovementPhysics An exploded mechanical watch whose Swiss lever escapement is simulated, not animated.
  • RingmakerAstronomy Backlit planetary rings with shepherd moons, wavy gap edges, propellers and waves.
  • Gravity TurnPhysics A two-stage rocket flies pad to orbit on a live blueprint, max-Q and all.
  • Rubens' TubeSound Gas flames on a brass pipe rise and dip with the standing sound wave inside.
  • Wind TunnelFluids A lattice Boltzmann wind tunnel: draw any shape and watch it shed vortices.
  • Leapfrogging VorticesFluids Smoke rings take turns slipping through each other, from pure vortex dynamics.

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

← More from Emergent Mind Labs