A second torus is read along the same tube circles
Two tori met in closed form only with collinear axes, and every other position was marched (#272): two pipe bends meeting at a corner, a fillet against a bend, two rings linked like a chain. The documentation called the general curve "up to degree 16". But a torus is bicircular, and that bound is not reached. On the first torus's tube circles, w = P − C₂ gives |w|² = |D|² + R² + r² + 2Rr cos v + 2(R + r cos v) D·e(u) + 2r sin v D·a₁, with D = C₁ − C₂. The parts of (R + r cos v)² + r² sin² v of degree two cancel, so |w|² is of degree one in each angle, and so is w·a₂. The second torus's equation (|w|² + R₂² − r₂²)² − 4R₂²(|w|² − (w·a₂)²) is then of degree two in each, like a quadric's. So each tube circle meets the second torus in up to four points, and the curve is of degree eight.
So the sweep of ADR 0049 reads it unchanged. The other surface became an enum of a cylinder, a cone or a torus. Each gives its equation F(u, v), its signed distance, a bound on |F| within confusion from the largest gradient of its equation, and its moves for snapping. Like a cylinder's radius, a torus's minor radius is offset exactly (an offset torus is a torus), so a torus touching within confusion is moved by one translation or one change of minor radius. The fit reads the second torus's angles as angles on both sides.
A shared tube circle. Pipe bends joined end to end share a tube circle: the minor radii are equal, and the centre circles touch at its centre. The tori touch all along it, and F vanishes to second order on the line u = u₀. The event search then meets a curve of common zeros and gives up. But each coefficient of v, of degree two in u with a double zero at u₀, factors as (1 − cos(u − u₀))(p + q cos(u − u₀) + s sin(u − u₀)). The quotient is again a trigonometric polynomial, of degree one in u, and its zeros are the rest of the curve. So the circle is found and divided out, and the rest is swept as before:
- Finding it. The circle's centre lies on the first centre circle where
e(u₀)is across(C₁ − C₂) × a₁anda₂ × a₁, giving at most four candidates. The circle is accepted where sixteen of its points lie within confusion of the second torus, with parallel normals. - Touching points. Points where the rest touches are read from the quotient alone, within the bound
Fhas across from the circle, where1 − cos(u − u₀)is two. They are not moved, since the tori touch along the circle anyway, and points on the circle are dropped fromcontact_points. - The fit. Where the rest of the curve crosses the circle the normals are parallel, so every loop's tangent there is stepped, as through a crossing.
The circle comes back from OcticCurve::shared_circle and is routed as a tangent curve. With no loops left, it is a TangentCircle.
A circle of one torus can lie on the other in two more ways: as a latitude circle of the other, or as a Villarceau circle of either. On a latitude circle the tori cross, and F vanishes only to first order on u = u₀, which no trigonometric polynomial factor takes out.
A circle of one torus on the other (#348). Neither needs a factor taken out; each needs the right torus to read along.
- A tube circle of the first on the second, crossing it. Read along the first's tube circles,
Fvanishes on the lineu = u₀, and the search for the points where the tori touch subdivides that line of common zeros to its depth: seconds of work before it gives up (8 to 15 s for the issue's pair), and the pair was then marched. Read along the second's, the circle is a latitude circlev = v₀: on each tube circle one root among the four, a branch like any other, and the sweep reads it. So the circle is now looked for first, in microseconds:u₀is a zero ofFalong any circlev = v*, a trigonometric polynomial of degree two inusolved in closed form, and a simple one unless∂F/∂uvanishes there too;v*is a golden section of the turn, off the quarter turns a symmetric pair touches or turns at. Each zero is checked by sixteen points of its tube circle within confusion of the other surface. A first version solved all five coefficients ofvforu₀, which cost up to 3% on the octic benches; one circle costs one solve. Where one lies on it,torus_againstgives up at once, andTorus::intersect_exactreads the pair along the second torus's tube circles and swaps the curve's operands back (OcticCurve::operands_swapped, as a cylinder or a cone against a torus is), so the caller's order is kept: the first surface's parameters first in the uv curves. The swap calls the reading, notintersect_exact, so it does not recurse; where the second torus's tube circles lie on the first too, both readings give up and the pair is marched. The check also stops at once a cylinder holding a tube circle, which took the same path. - A Villarceau circle. In the half angles
s = tan(u/2)andt = tan(v/2), the bitangent plane through the centre meets the torus where((R + r) + (R − r) t²)(1 − s²) − 2√(R² − r²) t (1 + s²)vanishes,(a − bt)² − s²(a + bt)²witha = √(R + r)andb = √(R − r). So each Villarceau circle iss (a + bt) = ±(a − bt), of degree one in each: one point on each tube circle and one on each circlev = v₀. Read along the tube circles of the torus it is a Villarceau circle of, it is one root among four, again a branch like any other; the tori touch at two of its points, where the rest crosses it. No factor is divided out. Where it is a tube circle of the other torus, the swap above reads it along this one's. It was read in one order for some placements only because of how the sweep splits its stretches: the branch winds once round the tube circles asugoes once round, so every anglevthe branches are ordered from is crossed somewhere, andsplittook the first angle crossed once, which here was crossed just short of the stretch's end. The next stretch was cut just short of its end again, and so on to the depth limit. Of the angles crossed as few times, it now takes the one leaving the shortest longest piece. - Crossings within rounding. Moved
1e3from the origin, the tori sharing a Villarceau circle came back sampled (ADR 0051): their coordinates rounded by1e-13, the points where they touch are touching only within that rounding, and the move that closes one gap leaves the other open by about as much. Each crossing is then a hyperbolaF₀ + ½ (a δu² + 2b δu δv + c δv²) = 0,F₀the rounding ofFthere, opening about√(2 |F₀| / max(|a|, |b|, |c|))across. Nearer the crossing than a few times that, the two points on a tube circle are within the rounding of each other, and Newton's method from a branch's line through the crossing landed on either, or on none: the loop's points jumped by1e-7, and its fit split down to its sample limit. A crossing now keeps that width (Crossing::apart), and within four times it the branches are read on their lines through the crossing; the fitted loops stay within a quarter of confusion of both tori. Moved1e7, a centre that is not a whole number rounds by up to2e-9, which parts the curve√(2ε / κ), about1e-4, from each point where the tori touched: by ADR 0057 no longer a contact but another pair, and no reading can answer it as the reference one. The judge leaves that translation out for those tori only.
Each configuration, a tube circle of either torus on the other as its latitude circle and a Villarceau circle of the first as the second's tube circle or latitude circle, at several radii, turns and placements, is read exact and complete in both operand orders, with as many curves and contact points either way, one curve on the shared circle, and uv curves on both tori. They are in the similarity judge (ADR 0051) in both orders, with the order itself as one more comparison.
Distance near crossings. The loops through a crossing slid to every distance (ADR 0049), at three evaluations of the curve per step. Two tori crossing where they touch made this the dearest call in the fit: side by side, 157M instructions. Away from the crossing the surfaces cross at an angle and the first order is right, so CurveFamily::slides_along now takes the point. The octic family slides only where the normals are within a sine of 0.25 of parallel, which brought the call down to 74M and the pipe bends from 46M to 15M. The quadrics' families ignore the point.
Considered options
- A resultant of degree 16, the bound the documentation gave: rejected. The equation along a tube circle is a quartic, as for a quadric, and the sweep already reads it.
- Divide out every shared circle: rejected for a latitude or Villarceau circle (#348). A latitude circle leaves a factor that is not a trigonometric polynomial, and the half-angle charts of the issue's directions would divide it out only on the reading that gives up; the other torus's reading already holds it as a branch. A Villarceau circle is of degree one in both half angles and already a branch of the sweep. Only a tube circle shared by both, where the tori touch along it and no reading sees a simple branch, is divided out.
- Slide everywhere on a loop through a crossing: kept as the fallback near crossings only, for the cost above.