The curve is a real torus knot, parametrized on the surface of a torus of major radius R and minor radius r:
x(t) = (R + r·cos(qt))·cos(pt)
y(t) = (R + r·cos(qt))·sin(pt)
z(t) = r·sin(qt), t ∈ [0, 2π]
When gcd(p, q) = 1 this traces a single closed loop — the torus knot T(p, q). When d = gcd(p, q) > 1 it splits into d mutually-linked copies of T(p/d, q/d), spaced evenly around the torus core: a torus link, not a knot.
Every frame the sampled 3D curve is projected onto the plane perpendicular to the current view direction (exactly the parallel projection used to define writhe via the Gauss integral). Every pair of non-adjacent segments is tested for a 2D intersection; where two strands cross, the one with smaller camera-space depth is "over", and the crossing sign is the handedness of (tangentover × tangentunder) — the same convention used to sign crossings in a knot diagram.
Writhe w(D) = Σ over all crossings sign(c)
Reidemeister I changes w by ±1 (adds/removes a single loop)
Reidemeister II, III leave w unchanged
That is the core subtlety this simulator makes visible: writhe depends on the projection — it is a property of a specific diagram, not of the knot itself, which is why it changes as you rotate the same, unmoving 3D curve. The crossing number shown as "theoretical minimum" is different: for a coprime torus knot it equals min(p(q−1), q(p−1)) (Murasugi's theorem) and does not depend on viewing angle — genuine topological invariants like this, or the Alexander polynomial ΔT(p,q)(t) = (tpq−1)(t−1) / [(tp−1)(tq−1)], are exactly the quantities knot theory builds because raw diagrams like the one you're rotating are not themselves invariant.
- p, q sliders — choose the torus knot/link; gcd(p,q) determines whether you get a single knot or a multi-component link.
- Auto-rotate speed — orbits the camera continuously so you can watch the live crossing count and writhe fluctuate with the projection in real time.
- Show crossing signs — marks each detected crossing with a green (+1) or red (−1) dot at the over-strand point.