HomeArticlesGeometry

Torus Knots: Winding a Curve Around a Doughnut Until It Ties Itself

How two coprime integers p and q generate an entire family of knots, and how a renderer turns that curve into a shaded tube.

mysimulator teamUpdated June 2026≈ 7 min read▶ Open the simulation

A knot living on a doughnut

A torus knot is the simplest family of knots in mathematics, and also one of the most visually rewarding: pick two coprime integers p and q, wind a single closed curve p times around the central hole of a torus and q times through the tube, and the strand closes into a genuine knot. Coprime means gcd(p, q) = 1 — if the two integers share a common factor d, the curve does not close into one strand at all; it splits into d separate interlinked loops, a torus link rather than a torus knot.

x(t) = (R + r·cos(qt))·cos(pt)
y(t) = (R + r·cos(qt))·sin(pt)
z(t) =  r·sin(qt)          for t in [0, 2π]

R is the distance from the centre of the tube to the centre of the torus, r is the tube radius. Every point of the curve stays glued to the torus surface because the parametrisation is really "walk around the big circle p times while walking around the small circle q times" — exactly the Lissajous-figure trick, lifted from a flat plane onto a doughnut.

live demo · a (p,q) torus knot traced as a closed parametric curve● LIVE

The trefoil and its neighbours

The (2, 3) torus knot is the trefoil — the simplest knot that cannot be untied without cutting it, and the first entry in every knot table. The (2, 5) knot is the cinquefoil (Solomon's seal knot); (3, 4) is the classic "(3,4)-torus knot" often drawn in topology textbooks with eight crossings. Swapping p and q traces the same knot from the other winding direction, so (p, q) and (q, p) are equivalent — the curve just gets parametrised differently.

Two invariants describe how tangled a torus knot is. The crossing number, the minimum number of times the curve crosses itself in any planar diagram, is min(p(q−1), q(p−1)). The genus — the minimum number of handles on an orientable surface the knot bounds — is (p−1)(q−1)/2. Both grow roughly with p·q, which is why high-order torus knots with small tube radius look almost like a solid braided rope: the strand has so many self-crossings in projection that the eye reads it as texture rather than as a single line.

Rendering it as a solid tube

A parametric curve has no thickness, so a renderer builds a tube mesh by sweeping a small circular cross-section along the curve using a Frenet-like frame: at each sample t, compute the tangent (the derivative of the curve), then a normal and binormal perpendicular to it, and place a ring of vertices around that local frame. Chaining consecutive rings into quads (two triangles each) gives a closed watertight tube. The naive Frenet frame can twist unpredictably wherever the curvature passes through zero, so production code — including three.js's TubeGeometry, which this simulation uses — instead propagates a parallel-transport frame along the curve, carrying the previous frame forward and only rotating it by the amount needed to stay perpendicular to the new tangent. That keeps the tube's cross-section from flipping or twisting as p and q change.

Iridescent shading: fresnel, not colour

The shifting, oil-slick colour on the surface is a fresnel effect: reflectivity depends on the angle between the view direction and the surface normal, near-grazing angles reflect almost all incident light while head-on angles let more through, so a curved tube naturally bands from dark at the centre to bright at the silhouette. Combining that view-dependent term with a hue that cycles along the tube (driven by the same parameter t used to build the geometry) produces the shimmering, soap-bubble colouring without a single texture image — it is pure geometry and a dot product between the normal and the view vector, evaluated per fragment in the shader.

Frequently asked questions

Why must p and q be coprime for a torus knot?

If p and q share a common factor d > 1, the parametric curve does not close after one pass — it returns to a different starting phase and must be traced d separate times to close, producing d linked loops (a torus link) instead of a single knotted strand.

What is the simplest non-trivial torus knot?

The (2, 3) torus knot, better known as the trefoil — three crossings, the smallest knot that is topologically distinct from an unknotted loop.

Why does the surface look iridescent instead of a flat colour?

The shading uses a fresnel term based on the angle between the surface normal and the camera, not a fixed material colour, so the same tube looks dark where you're looking straight at it and bright, colour-shifted at grazing silhouette angles — the same optical effect that makes soap bubbles and oil films shimmer.

Try it live

Everything above runs in your browser — open Torus Knot and change the parameters while it is running. Nothing is installed, nothing is uploaded, the whole model lives in one tab.

▶ Open Torus Knot simulation

What did you find?

Add reproduction steps (optional)