CCN
The donut and the bacteriumLearn · from Clown Run

The donut is a torus

In Clown Run the clown runs on a giant donut. Mathematicians call its shape a torus. This page starts where anyone can start and climbs, one level at a time, to the mathematics of a first year at university; stop wherever you like. The window below is live: turn it with a finger or the mouse, and change the donut with the sliders.

Level 1 · from about 12 Level 2 · from about 14 Level 3 · from about 16 Level 4 · first year at university Computing and biology

Cut open and laid flat: the arrows show which edges are glued together. Tap to move the point.

Level 1 A circle spun round a circle

  1. How to make one. Draw a small circle. Now spin it around a line that does not touch it, like a hoop rolling round a pole far away. The surface it sweeps out is a torus: the skin of a donut, a rubber ring or a bagel.
  2. Two sizes describe it. The big radius R is how far the middle of the dough is from the middle of the hole. The small radius r is how fat the dough is. In the window, move the two sliders and watch. The game's donut has R = 3 and r = 1.25 (in the game's own units).
  3. Two ways round. On a ball, every way round is the same. On a torus there are two different ones: the long way, round the hole (the angle θ, "theta"), and the short way, through the hole and over the top (the angle φ, "phi"). Move the θ and φ sliders: the point walks the long way and the short way.
  4. The clown never falls off. When he runs all the way round the long way, he comes back to where he started. Try it in the flat picture: the left and right edges are glued together, so a point leaving one side comes back in on the other, as in many old video games. Glue the top and bottom too, and the flat square curls up into a torus.
  5. Try it with paper. Take a rectangle of paper. Tape the long edges together: a tube. Now bend the tube round to tape its two ends together. (Paper will crumple; a rubber sheet would not.) That is a torus, and that is exactly the square in the window.

Level 2 Angles, area and volume

  1. A point on a circle. On a circle of radius r, the point at angle φ is at (r cos φ, r sin φ). The small circle of the torus is such a circle.
  2. The volume (Pappus's rule). Spin a flat shape round an axis: the volume swept is its area times the distance its centre travels. The small circle has area πr², and its centre travels 2πR. So the volume is V = πr² × 2πR = 2π²Rr². For the game's donut, V = 2π² × 3 × 1.25² ≈ 92.5 cubic units.
  3. The area of the skin works the same way: the small circle's length, 2πr, times the 2πR its centre travels: A = 4π²Rr. The game's donut: A ≈ 148.0 square units, which is all the glaze the clown could ever run on (he keeps to the band over the top: tick "the clown's world").
  4. Check with the window: the readout under the sliders works out V and A as you move R and r. Double R: both double. Double r: the area doubles, but the volume goes up four times. Why?

Level 3 Equations, normals and the game's coordinates

  1. The parametric equations. Spin the point (R + r cos φ, r sin φ) round the vertical axis by θ:
    x = (R + r cos φ) cos θ,   y = (R + r cos φ) sin θ,   z = r sin φ,   0 ≤ θ, φ < 2π.
  2. One equation for all its points. A point (x, y, z) is on the torus exactly when its distance from the axis, √(x² + y²), less R, and its height z, make a right triangle with hypotenuse r:
    (√(x² + y²) − R)² + z² = r².
  3. Three kinds. When R > r the torus has a hole: a ring torus. When R = r the hole closes to a point: a horn torus. When R < r the dough passes through itself: a spindle torus. Slide R below r in the window to see it.
  4. The arrows at the point. Moving θ a little moves the point along the orange arrow; moving φ, along the green one. These are the derivatives ∂X/∂θ and ∂X/∂φ of the position X(θ, φ). Their cross product, made one unit long, is the blue arrow, the normal: straight out of the glaze. The clown stands along it, and gravity in his world pulls against it.
  5. The game's own coordinates. The rules know nothing of angles: the clown is at whole numbers (x, y), x from 0 to 180 000 round the ring and y from −16 000 (inner edge) to 16 000 (outer edge). Only the drawing turns them into angles: θ = 2πx / 180 000 and φ = 90° − 80° × y / 16 000. (Whole numbers make every game replay exactly the same on every computer: the CCN Cloud replays your moves to check your score.) Running past x = 179 999 brings him back to 0: arithmetic modulo 180 000, the long way round of Level 1.

Level 4 Metric, curvature and Gauss–Bonnet

  1. The first fundamental form. With X(θ, φ) as above, E = Xθ·Xθ = (R + r cos φ)², F = Xθ·Xφ = 0, G = Xφ·Xφ = r². So ds² = (R + r cos φ)² dθ² + r² dφ²: the coordinate lines meet at right angles everywhere (F = 0), and the circles of the long way are longer outside (cos φ > 0) than inside.
  2. Area by integration. dA = √(EG − F²) dθ dφ = r (R + r cos φ) dθ dφ, and ∫₀^2π∫₀^2π r (R + r cos φ) dθ dφ = 4π²Rr: Level 2's answer, now from first principles (the cos φ term integrates to nothing).
  3. Gaussian curvature. From the second fundamental form (with the unit normal N, L = Xθθ·N, M = Xθφ·N, N₂ = Xφφ·N), K = (L N₂ − M²) / (EG − F²), which here is
    K = cos φ / ( r (R + r cos φ) ).
    Outside (cos φ > 0) the glaze curves the same way in every direction, like a ball: K > 0. Inside, round the hole, it is a saddle: K < 0. On the top and bottom circles, K = 0. Tick "colour by curvature": red is positive, blue negative, white zero; the readout gives K at the point.
  4. Gauss–Bonnet. ∫∫ K dA = ∫∫ cos φ dθ dφ = 0. For any closed surface, ∫∫ K dA = 2πχ, where χ is the Euler characteristic; so the torus has χ = 0, genus 1 (one hole), however it is stretched. Every positive bit of curvature outside is exactly paid for by negative curvature inside.
  5. The flat torus. The square with opposite edges glued has K = 0 everywhere; it is a torus too, the same topologically, different metrically. It cannot sit in ordinary 3D space without bending (it can in 4D: the Clifford torus). The game's world, x modulo W across y in a closed interval, is a band: S¹ × [−Y, Y], an annulus, laid over the top of the embedded torus.
  6. Checked in the Wolfram Language (the same steps, done symbolically):
    X[th_, ph_] := {(R + r Cos[ph]) Cos[th], (R + r Cos[ph]) Sin[th], r Sin[ph]};
    Xt = D[X[th, ph], th]; Xp = D[X[th, ph], ph];
    {EE, FF, GG} = Simplify[{Xt.Xt, Xt.Xp, Xp.Xp}];
    dA = Simplify[Sqrt[EE GG - FF^2], R > r > 0];
    n = Simplify[Cross[Xt, Xp]/dA, R > r > 0];
    K = Simplify[(D[X[th, ph], th, th].n D[X[th, ph], ph, ph].n - (D[X[th, ph], th, ph].n)^2)/(EE GG - FF^2), R > r > 0]
      (* Cos[ph]/(r R + r^2 Cos[ph]) *)
    Integrate[dA, {th, 0, 2 Pi}, {ph, 0, 2 Pi}, Assumptions -> R > r > 0]     (* 4 Pi^2 r R *)
    Integrate[K dA, {th, 0, 2 Pi}, {ph, 0, 2 Pi}, Assumptions -> R > r > 0]   (* 0 *)

The bacterium's tail

Biology The flagellum

  1. The name. The tails of the living sprinkles are flagella (one: a flagellum), Latin for "a little whip", from flagrum, a whip.
  2. What it does. Many bacteria swim with them. In Escherichia coli each flagellum is a long, thin, stiff helix (about 10 µm long, several times the length of the cell, and 20 nm thick), joined by a flexible hook (a universal joint) to a motor in the cell's wall. The motor turns the helix like a corkscrew, at up to about 300 turns a second, and the turning helix pushes the cell along.
  3. Runs and tumbles. When the motors turn one way, the flagella bundle together behind the cell and it swims straight: a run. When some turn the other way, the bundle flies apart and the cell tumbles, pointing somewhere new. Tumbling less often when things are getting better (more food) steers the cell up the gradient: chemotaxis.
  4. The game cheats, a little. The game's tails bend, a wave running from root to tip, as a sperm cell's tail does (that kind of flagellum, in cells like ours, bends; it does not turn). A bacterium's flagellum does not bend at all: it is rigid and it turns; the wave you seem to see running along it is only the helix turning. Switch the window between the two and compare.

Computing How the tail is animated, in JavaScript and in the Wolfram Language

  1. A chain of four segments. Each tail is four short rods, each hung from the end of the one before (in three.js, each is a child of the previous one, so turning one turns all those after it). Each frame, every segment is turned by a sine of the time, a little later than the one before it: the lag (0.9 per segment) is what makes a wave run down the tail, root to tip. The four tails of a sprinkle are out of step (1.3 apart), and each sprinkle has its own phase.
  2. The game's JavaScript (games/clownrun/clownrun.js; now is the time in milliseconds):
    // segment j of tail i: a turn about the vertical (a lash from side to side)
    // and a smaller one about the horizontal, each a sine of the time, lagging down the chain
    d.tails.forEach((segs, i) => segs.forEach((seg, j) => {
      seg.rotation.y = Math.sin(now / 55 - j * 0.9 + i * 1.3 + d.phase) * 0.5;
      seg.rotation.x = Math.cos(now / 80 - j * 0.7 + i) * 0.2;
    }));
  3. The same in the Wolfram Language: the chain written out as a product of matrices, a move along the tail and the two turns for each segment, giving the joints' positions:
    flagellum[t_, i_, phase_ : 0] := Module[{m = IdentityMatrix[4], pts = {{0., 0., 0.}}},
      Do[
       m = m . If[j > 0, TranslationTransform[{0, 0, -0.045}]["TransformationMatrix"], IdentityMatrix[4]] .
         RotationTransform[0.2 Cos[t/80 - 0.7 j + i], {1, 0, 0}]["TransformationMatrix"] .
         RotationTransform[0.5 Sin[t/55 - 0.9 j + 1.3 i + phase], {0, 1, 0}]["TransformationMatrix"];
       AppendTo[pts, (m . {0, 0, -0.045, 1})[[;; 3]]], {j, 0, 3}];
      pts]
    
    Animate[Graphics3D[Table[{Hue[i/4], Tube[flagellum[t, i, 1.7], 0.007]}, {i, 0, 3}],
      PlotRange -> {{-0.2, 0.2}, {-0.2, 0.2}, {-0.2, 0.02}}], {t, 0, 2000}]
  4. The two agree. Tail 1 of a sprinkle with phase 1.7, at t = 1000 ms: the joints, from three.js (the game's own scene graph) and from the Wolfram Language (version 15.0), are the same to six decimal places:
    Jointthree.jsWolfram Language
    1(−0.015933, 0.004996, −0.041787)(−0.015933, 0.004996, −0.041787)
    2(−0.049687, 0.016010, −0.069434)(−0.049687, 0.016010, −0.069434)
    3(−0.088740, 0.031844, −0.085217)(−0.088740, 0.031844, −0.085217)
    4(−0.122691, 0.052717, −0.106114)(−0.122691, 0.052717, −0.106114)
  5. A real bacterium's tail is simpler to write: a rigid helix, and the motor turns the whole of it. In this page's window, the JavaScript builds the helix once and turns it (tail.rotation.z += omega * dt); in the Wolfram Language the helix at time t is
    helixTail[t_, w_ : 2 Pi] := Graphics3D[{Orange, Tube[Table[{0.2 Cos[2 Pi s - w t], 0.2 Sin[2 Pi s - w t], -s}, {s, 0, 3, 0.02}], 0.04]}]
    Animate[helixTail[t], {t, 0, 1}]
    Turning the helix by an angle ωt is the same as sliding the wave along it by ωt / 2π turns: that is the travelling wave the eye sees.

Read more

  1. N. C. Darnton, L. Turner, S. Rojevsky, H. C. Berg, "On torque and tumbling in swimming Escherichia coli", J. Bacteriol. 189 (2007): PMC1855780.
  2. Y. Sowa, R. M. Berry, "Bacterial flagellar motor", Q. Rev. Biophys. 41 (2008).
  3. S. Nakamura, T. Minamino, "Flagella-driven motility of bacteria", Biomolecules 9 (2019): PMC6680979.
  4. The mathematics of Level 4: any first course in the differential geometry of curves and surfaces (the torus is the standard example of the Gauss–Bonnet theorem).