Skip to content

Tube circles meet a cylinder or a cone in up to four points

A torus met a cylinder or a cone in closed form only when they were coaxial, and every other position was marched (#271): a pipe through a fillet, a drill axis off a bend, a cone through a toroidal edge round. The torus's point P(u, v) = C + (R + r cos v) e(u) + r sin v a is of degree one in the cosine and sine of each angle, and a cylinder's or a cone's equation G(P) = (P − Q)ᵀ M (P − Q) + c is quadratic: M = I − d dᵀ and c = −ρ² for a cylinder, M = d dᵀ − cos²φ I with Q the apex and c = 0 for both nappes of a cone. So F(u, v) = G(P(u, v)) is a trigonometric polynomial of degree two in each angle, 5 × 5 coefficients in 1, cos, sin, cos 2, sin 2. On the tube circle at u it is A cos 2v + B sin 2v + C cos v + D sin v + E, a quartic in tan(v / 2) that solve_trig already solves: up to four exact points per tube circle.

The curve is of degree eight. Unlike a plane or a sphere (ADR 0048), the points on a tube circle are not the two signs of one root, so the quadrics' walk does not read it. Instead, the curve is read from its events and swept between them:

  • Events. Points appear and vanish in pairs where a tube circle grazes the other surface, at the common zeros of F and ∂F/∂v. Two branches cross where the surfaces touch, at the common zeros of ∂F/∂u and ∂F/∂v with F within confusion. Both are common zeros of two trigonometric polynomials. The new common_zeros finds them by subdivision: four charts u = α + 2 atan s, α in {0, π}, on which a polynomial times (1 + s²)^K (1 + t²)^K is a polynomial in Bernstein form over the unit square. A box whose coefficients share a sign is dropped; one whose interval Jacobian keeps away from zero holds at most one zero, which Newton's method finds to 1e-12. A box still undecided at a side of 2⁻³² is a cluster, a zero of higher multiplicity. One that needs more than 200 000 boxes holds a curve of zeros, and the search gives up.
  • Classification. Where the surfaces touch, the Hessian of F decides. Negative, the curve crosses itself there, its two slopes read from the Hessian. Positive, the point is alone, the surfaces touching and parting. Nearly singular, the contact is of higher order. A grazing tube circle opens its pair of points backward in u when ∂F/∂u · ∂²F/∂v² > 0.
  • Sweep. Between consecutive event angles, every tube circle holds the same number of points, in the same order from an angle no branch crosses. That angle is taken off the middle of a gap between two points (a golden fraction of it, since a symmetric curve turns back at the middle). Failing that, one of sixteen spread angles is used. If every candidate is crossed, the piece is split at the crossings of the candidate crossed least, at most eight times. At each event boundary a branch runs through, a pair closes, a pair opens, or two pairs swap at a crossing. Following those joins gives the loops.
  • Evaluation and fit. Each pass of a loop over a piece gets an equal share of its parameter. The angle u runs over it through a shape that slows where the piece's ends turn back (sin², 1 − cos or sin), so the tangent stays finite. The points come from the quartic on the tube circle. Near a crossing, the solver merges the two close roots into a double one, so there the points come from the slopes and a Newton step in v. The fit is the quadrics' (ADR 0036), through CurveFamily, which learned a component type of its own and whether a component slides along its family.

Touching within confusion. A cone's apex within confusion of the torus is moved onto it, and it then lies on the curve's crossing. Points where the surfaces are within confusion of touching are closed the same way: the other surface is moved by the one translation that closes every gap, or a cylinder's radius by the one change. When no single move closes them all to a thousandth of confusion, the result is NotAnalytic, rather than points left that far from touching but read as touching.

Tangency along a curve happens only coaxially. A contact curve's normals meet both the torus's centre circle and the other surface's axis, and for a circle and a line that happens along a curve only when the line is the circle's axis. That case and its rings are read before. A cylinder holding a tube circle (F vanishing on a whole u) gives a curve of zeros in the event search, which gives up.

NotAnalytic stays for:

  • a horn or spindle torus, whose tube circles cross on its axis, where its normal fails;
  • a cylinder or a cone holding a tube circle, the curve then splitting off that circle;
  • contact of higher order than a crossing or a point;
  • several near-contacts that no single move makes exact.

The typed call classifies in 0.6–1M instructions, mostly the subdivision, and intersect fits the loops in 4.8–10.5M. Most of the typed call is the subdivision copying and quartering its boxes, left to profile when a consumer needs it faster. The result enums hold the curve boxed, Octic(Box<OcticCurve>). Inline, the curve's 600 bytes made every coaxial result that size, and the coaxial torus–cone call took 7% more, all in copying it.

Considered options

  • A resultant in u, the discriminant of each tube circle's quartic, whose roots are the grazing angles: rejected. It is a trigonometric polynomial of high degree. A symmetric curve grazes on two tube circles at once, a double root whose sign does not change, and a crossing shows only as a double root too. The subdivision certifies each zero and tells the two apart.
  • The cylinder's or the cone's generators, as for the quadrics: rejected. A line meets a torus in a quartic of its own, not a quadratic whose root has a sign, and the points along a generator have no closed form better than along a tube circle.
  • Keep marching: rejected. The issue's cases are common in parts, and the march neither certifies the loops nor finds isolated contact points.