A trimmed surface clips the intersection of its basis
A face of a model lies on a patch of its surface, not on the whole surface: two faces on crossing cylinders meet along an arc of the quartic, not the whole loop, and two patches of a cone and a cylinder along one of its generators meet along a bounded piece of a curve that, untrimmed, runs to infinity and makes the march cut it and report Incomplete (issue #266, after the box parameter of #264 and #265 was closed). TrimmedSurface<S>, built by surface.trimmed(u_range, v_range), is the surface restricted to a parameter rectangle, and intersect takes it with any surface, in either order.
The intersection of two surfaces, one or both trimmed, is computed in three steps:
- Solve on the bases. The pair is routed as its two bases are, through the closed-form pair table, so an exact pair stays exact. A march is held
withinthe box of the trimmed sides (the intersection of the two boxes when both are trimmed), grown by 1 % of its diagonal so a branch is traced a little past the ranges: a branch ends on the box and is not reported as cut. Boxes that do not meet return an empty exact result without solving. - Clip each curve through its curve in parameters. A curve's curve in a trimmed side's parameters (the exact one, the march's fit, or one mapped within a tenth of the confusion distance when the result has none) is intersected with the sides of the parameter rectangle, and with its copies shifted by whole periods along a periodic direction. The curve is cut at the crossings and at the ends of a stretch along a side, and each piece is kept when its middle lies in the rectangle, within confusion in space past an end. Pieces adjacent after the cut are merged, a piece shorter than confusion is dropped, and a periodic curve cut on both sides of its seam keeps the piece across the seam whole, its range running past the period. An unbounded curve, a line, is first bounded to where it leaves the trimmed sides' box. A curve that cannot be mapped to parameters, such as one lingering at a cone's apex, is cut where 64 samples of it enter or leave the rectangle, refined by bisection. Amended (#314): a fit whose
deviationexceeds the confusion distance is mapped as well, as a march's fit in the parameters of a surface whose parameters turn fast along a straight cut (a plane across a flat ring of a revolution surface), whose 0.07 would end the pieces 0.025 from the boundary. Amended (#315): a fitted closed loop, marched or fitted from a closed form, is a periodic B-spline, its period its length, so it keeps the piece across its start whole too, where it came back as two pieces. Its curves in parameters stay clamped B-splines over one turn, since one around a periodic direction ends a period away and no periodic curve holds it; the piece across the start gets them followed by their copy moved on by one turn, in parameter and in value. Moving the loop's start out of the ranges instead would have kept the curves non-periodic, but the pieces would no longer share the curve of the bases, and a piece across the start could still not be rebuilt from the untrimmed loop. - Filter the rest. A contact point is kept when its parameters lie in the ranges of each trimmed side. Two patches of one surface are coincident when a 9 × 9 grid of either rectangle has a point in the other; otherwise the result is empty. Amended (#406): the grid holds the rectangles' edges, so two patches sharing only an edge, two stacked faces of a cylinder or two squares of a plane side by side, read as coincident with no curve, and a B-rep builder needs the edge. The patches are now coincident only where they overlap with area. The ranges are compared in the first basis's parameters, the second's mapped there when the two bases parametrize the surface alike: the same parameters, or parameters shifted, reversed or swapped, as two frames of one cylinder on its axis or two frames of one plane turned by a quarter give. The map is read from the derivatives at the middle of the first rectangle and checked at the corners of both within confusion. In each direction the two ranges, modulo the period, have common pieces: a span longer than confusion in space (the speed taken at the middle of the first rectangle), or a touch where an end of one is within confusion of an end of the other; on a periodic direction there can be one at each end of the first range, as two half cylinders share two generators. A span in both directions is an overlap with area: coincident, with no curve, also where a further edge is shared, as before. Otherwise each span and touch is a shared edge, reported as an
IntersectionCurve: the first basis's iso-curve at the touch, over the span, with a line in the parameters of each patch (the second's moved by whole periods so its middle lies in the ranges as written),tangentsince the patches touch along it and do not cross it, and asdeviationhow far the second's boundary lies from it, at most confusion. A touch in both directions is a corner, a contact point, as is an edge that collapses to a point. Two patches whose ranges are apart in a direction that collapses at their common point, two sectors of a sphere meeting only at its pole, are reported apart: the ranges are compared, not the points. Bases parametrized otherwise, as two frames of a sphere with different poles, a plane's frame turned by another angle, or a B-spline reparametrized, keep the sampled check and read as coincident when they only touch: finding their shared edges needs each side of one rectangle, a trimmed iso-curve, clipped to the other patch by the curve × trimmed surface clipping and mapped into both parameter spaces, a costlier path with no consumer yet. It is reopened when a pair shows it. The boxes of the two patches are now tested apart beyond confusion, so faces a hair apart still reach the check.
The result keeps the curve of the bases and says which piece of it lies on both patches: IntersectionCurve gains parameter_range, the curve's own bounds for an untrimmed pair (infinite for a line) and the piece for a trimmed one. One curve of the bases may give several pieces, each its own IntersectionCurve sharing the curve. The method and completeness of the bases' result are kept.
Considered options
- A box parameter on
intersect(#264, #265): rejected and closed. A box is not what a face carries, it does not clip exact curves, and the caller had to compute it. - Trim the curve itself, a
TrimmedCurveinIntersectionCurve: rejected.Curvehas no trimmed variant, and the field's type would change for every untrimmed result. A range beside the curve keeps the untrimmed result as it was, andTrimmedCurve::new(curve, range)builds the piece when one is wanted. - Clip by sampling the 3D curve: kept only as the fallback. Samples miss a curve that leaves the rectangle between two of them; the crossings of the curve in parameters with the rectangle's sides are found by the 2D intersection, which does not.
- Make
TrimmedSurfaceaSurfaceOperandwith its own basis kind: rejected. Every exact solver would have to clip, and a trimmed surface of a trimmed surface would be an operand too. The clipping is one function over trait objects, compiled once, after any solver. - Shift each curve in parameters by periods into the ranges: deferred. The curves in parameters stay those of the bases, which the trimmed surface evaluates the same;
Curve2Dhas no translation yet.
Consequences
- Breaking in Rust: a struct literal of
IntersectionCurveneedsparameter_range. - A curve and a trimmed surface do not intersect yet: the Python
intersectraisesTypeErrorfor the pair, and Rust has no implementation. A curve against the basis, filtered by the patch'scontains, does it meanwhile. Amended (#326): they do, in either order, by the same steps: the curve is intersected with the basis, a hit is kept when its surface parameters lie in the ranges (with the slack and the shift by periods of step 3) and reports their representative there, and an overlap is clipped as a curve of step 2, mapped to the basis's parameters and cut at the sides of the rectangle. The hits stay those of the basis's solver, so the method and completeness are kept. - A trimmed surface's projection is the basis's closest point when it lies in the ranges, otherwise the closest point on the boundary; another local minimum inside the ranges is not searched.