Skip to content

CAD kernel foundations · Part nine

Meshing a face

The grid in the parameter rectangle, the map that carries it into space, and the incremental triangulator that joins it up

Part eight discretised an edge, which is a curve, into a polygon. A face is a surface, and meshing it takes three separate steps: the points are chosen in a flat rectangle of parameters and carried into space by a map that distorts them, the boundary tessellated earlier has to be respected exactly, and something has to decide which point joins which. In this article we go through the three steps in the order a kernel runs them, and then check whether the deflection that was requested is the deflection the mesh delivers.

Working in the parameter plane

Part eight stated what a mesh must satisfy but said nothing about where the triangles are found. There are two places to look, and the choice shapes everything downstream.

Taken literally, the job (vertices lying on the surface, covering the face) sounds like work done in space: scatter points on the surface, connect them, and keep the ones inside the boundary. Each of these three steps is harder in space than it looks.

Putting a point on the surface. A point chosen in space is not on the surface, and getting it there means projecting it: an iterative solve against the surface, repeated for each point. Connecting the points. The Delaunay condition is a statement about circles in a plane. On a curved surface the equivalent needs geodesic distances, or a triangulation of the point set in space restricted to the surface afterwards, which is more machinery for a weaker result. Deciding what is inside. The boundary is a set of curves lying in the surface, so parity has to be counted along a path on the surface from the point to somewhere known to be outside, and every crossing on the way is an intersection of two curves on a curved surface, solved numerically. On a closed surface there is not even an outside to aim at: if we leave a point on a sphere in any direction, we come back to it.

The alternative uses the chart the face already carries. The surface is a map from a rectangle of parameters into space, and the face’s boundary is not stored only as curves in space: each edge also carries a curve in that rectangle, the pcurve of part five. So the problem is already written as a planar one: triangulate a region of the plane bounded by closed polygons. That problem is standard, and its predicates are arithmetic on two coordinates instead of numerical solves, cheap enough to run for every candidate point (section four shows that cheap is not the same as exact). We then push each vertex of the result through the surface map, and the triangles are in space, with their vertices on the surface by construction instead of by projection.

The difference in cost is large, and we can measure it. The map is cheap in one direction only. Evaluating a surface at a parameter pair costs about a microsecond whatever the surface is. Going the other way, from a point in space to the parameters that produce it, costs about four microseconds on a sphere (about one with the closed form part three printed) and, on a free-form surface with no starting guess, six to thirty-nine milliseconds. Even with a good starting guess it costs sixteen to two hundred and sixty times the forward evaluation. An algorithm whose points are created in the rectangle never pays this cost. An algorithm whose points are created in space pays it once for every point.

The difference is not only one of cost. When a kernel classifies a point in space against a face, it first runs a point-to-surface extremum search to recover the parameters, and then asks the same question in the rectangle that it would have asked anyway. There is no three-dimensional version of the test, only a three-dimensional entry point into the two-dimensional one.

What the parameter plane costs is regularity. The map is not an isometry: equal steps in the rectangle are not equal distances on the surface, and a well-shaped triangle in the chart can become a sliver in space. That distortion is the metric of part five, and the following sections deal with it: they give a rule for choosing the spacing in the rectangle so that the result on the surface is what was asked for.

A lattice for each surface type

The step from part eight is defined for a curve. A face is a surface, and turning one into the other is where the surface types start to differ.

The method is to lay down a lattice of points in the parameter rectangle, spaced by the step the sagitta relation gives, before any triangle exists. It is a closed-form calculation: no measurement, no iteration, and no geometry evaluated beyond the radii the surface already carries. Each surface type computes its own lattice, and the rules differ enough that we take them one at a time.

sphere 132 interior nodes one angular step, both axes, rows offset by half a step cone 48 interior nodes one step, taken at the widest radius, always torus 247 interior nodes two steps, one per radius, coupled to bound the cells the same deflection, the same angular ceiling, three lattices
The three surfaces that get a lattice, meshed to one deflection, each shown as the points its own rule places in the parameter rectangle and as the triangulation those points produce. Each surface follows a different rule. The sphere uses a single angular step along both axes and offsets alternate rows by half of it: in the rectangle drawn here no two neighbouring rows share a column, and every second row does. A staggered lattice is closer to the equilateral ideal than a square one, and it avoids handing the triangulator a grid of squares, where four points lie on one circle and the choice of diagonal is a tie. The cone computes its step once, at the widest radius it spans, and uses it the whole way down: the rectangle is uniform, and the cost shows on the surface below it, where the same number of divisions wraps a circle that has shrunk to almost nothing. Its rows along the ruling come from a length instead of an angle (the arc one circumferential step covers at that widest radius), with the count damped logarithmically so that a long cone does not get rows in proportion to its length. The torus takes two steps, one from the radius of the tube and one from the radius of the ring, and couples them so that neither direction can run away from the other. A plane and a cylinder have no column here because they get no lattice at all.
u v 0 2π −π/2 π/2 u v 0 2π 0 h sphere — 306 interior nodes cylinder — 0 interior nodes the parameter rectangle the parameter rectangle the surface the surface
Two surfaces meshed to the same deflection, each shown in its parameter rectangle and on the surface. Above, a sphere: the lattice shows as rows of interior points, offset by half a step so that neighbouring rows do not line up. The rectangle is evenly divided because the same angular step serves both axes, so the spacing is uniform in the chart and collapses on the surface, where the circles of constant latitude shrink to nothing and the triangles around each pole are small and crowded. Below, a cylinder at the same deflection, with an empty rectangle: 0 interior points against the sphere’s 306. This is expected. A cylinder is ruled (straight lines lie in it), so a triangle spanning the full height deviates from the surface by nothing, and the resolution the deflection demands is already present in the two rims, which were tessellated by the same rule one stage earlier. The interior of the rectangle needs no points.

A sphere uses one angular step for both axes, and offsets alternate rows by exactly half of it: the quincunx, the five-on-a-die pattern. There are two reasons for the offset.

The first is packing. The deflection depends on a triangle’s circumradius, not on the length of its sides: the worst deviation over a triangle whose corners are on a sphere is at its circumcentre, and is about ρ²/2R for a circumradius ρ. So asking how few points can meet a given deflection is asking how few points can cover the surface with discs of a given radius, and that question has a known answer. A square lattice needs one point per 2ρ² of area. A triangular one needs one per 3√3ρ²/2, which is 23 per cent fewer points for the same worst-case error. Staggering the rows is the cheapest way to move a grid towards that optimum: the lattice drawn in the figure has a row spacing 9 per cent off the equilateral ideal, where an unstaggered grid of the same step would be 41 per cent off.

The second reason is degeneracy. A square lattice puts four points on a common circle in every cell. The Delaunay condition does not choose between the two diagonals of such a cell (both satisfy it), so the choice falls to whichever way the arithmetic rounds, and neighbouring cells can round in opposite directions. As section four explains, the predicates that decide this are not exact, and a grid of perfect squares is the input on which an inexact in-circle test has nothing to go on. Staggering removes all of these ties by construction. Without it, the output depends on the floating-point unit as well as on the input.

What the sphere gives up is the poles. One angular step for both axes is right at the equator and increasingly wrong away from it, because the circles of constant latitude shrink while the step does not. The rectangle stays evenly divided (this is what the figure shows), and the unevenness appears on the surface as the ring of small crowded triangles around each pole. A sphere is not developable, so no direction avoids this. The step the relation returns is also multiplied by 0.7 before use, and the range is then divided by a whole number of those steps, so the lattice comes out about forty per cent finer than the relation asked for. This factor stands in for the measurement that, as section seven describes, is not otherwise made.

A cone computes its step once, at the widest radius it spans, and uses it the whole way down. This is forced. The sagitta relation gives a finer angular step for a larger radius, so the wide end is the strictest requirement; and because the lattice is a grid in the rectangle, every row has the same number of columns, so there is one step to pick and the only safe pick is the strictest. The cost is at the narrow end, where the same number of divisions wraps a circle that has shrunk to almost nothing, and the triangles crowd without any gain in accuracy.

Its rows along the ruling come from a length instead of an angle: the arc that one circumferential step covers at the widest radius, which makes the cells roughly square where they are largest. The count is then damped logarithmically, so that a long cone does not get rows in proportion to its length. The reason is that a cone is ruled: straight lines lie in it, so the interior rows add no accuracy, only better triangle shape. Since they are optional, their count grows with a logarithm instead of a multiplier.

A torus is the only surface here with two independent curvatures, so it is the only one that computes two steps: one from the radius of the tube and one from the radius of the ring. Left alone, the two would produce cells of an extreme aspect ratio on a thin torus, where the tube step is fine and the ring step coarse, and the triangulator would be handed slivers in both directions. So the two are coupled (each step is pulled towards the smaller of the pair), and a further floor forces more divisions around the ring in proportion to how thin the tube is. It is the only splitter that bounds its own cell shape instead of leaving it to the geometry.

It is also the only one that looks at the boundary before choosing. Instead of laying down a lattice of its own, it collects the parameter values the boundary already uses, thins them by the average boundary spacing, and uses those. The reason is sliver control: a lattice value that lands a hair away from a boundary value creates a triangle with no useful shape and no way to remove it later. This matters on a trimmed torus with a rich boundary. On a complete torus, whose only boundary is its two seams, there is nothing to align to, so it falls back to a regular grid, which is the case drawn in the figure.

A plane gets no lattice, because it has zero deviation from its own chords, so no interior point can improve anything. A planar face is also handed a different algorithm: a bare triangulation of its own boundary polygon, with no insertion stage at all. A circular cap bounded by a hundred-point circle comes out as a hundred nodes and ninety-eight triangles, which is n − 2, the exact count for a simple polygon.

A cylinder gets no lattice either, which is what the second figure shows. Its rectangle is empty (no interior points, only the two rows on the rims), while a sphere at the same deflection carries three hundred. A cylinder is ruled: through every point of it there is a straight line lying entirely in the surface. A triangle spanning the full height therefore has no deviation to correct in that direction, because the surface is straight there. The resolution the deflection demands is the resolution around the circumference, and that is already present in the two rims, tessellated by the same sagitta rule one stage earlier. So the interior of the rectangle needs no points.

The step is still computed for a cylinder, and still used, but to scale the parameter space the triangulator works in instead of placing points. If we set the aspect ratio of the rectangle from the step, an ordinary triangulation, which has no notion of what the parameters mean, produces well-shaped triangles anyway. This is a general technique: the metric of part five does not have to appear in every algorithm if it can be pushed into the coordinates the algorithm is handed. Every surface type gets this scaling, including the two that get no points.

The ruled cases save points but lose control of shape. A cylinder meshed this way has triangles as tall as the cylinder and as narrow as one circumferential step, and their aspect ratio follows the height-to-radius ratio. For display this does not matter. For anything that will later be refined, simulated on or offset, long thin triangles are a known source of trouble, and a mesher serving those callers needs a length criterion that the deflection rule does not supply.

Connecting the points: Bowyer–Watson insertion

We might expect one of two architectures, a structured grid or incremental insertion, and expect a given kernel to pick one. In practice it uses both, in a fixed order.

The boundary is meshed first, and it constrains everything after it. The lattice points then go in one at a time: each insertion deletes the triangles whose circumcircles the new point violates and refills the cavity this leaves. So the closed form decides where the interior points are, and the incremental triangulator decides how they connect.

This split explains an odd property: the lattice is computed as if the face were the whole rectangle, and points falling outside the face’s actual boundary are then discarded. A lattice that respected the boundary would have to know about it, and the boundary is a set of curves in the rectangle with holes, wrapping and everything else part seven described. It is cheaper to over-generate and reject, and the rejection test is the point-in-face test of part seven. Section six follows it point by point on a real face.

The algorithm that does the connecting is older and plainer than the machinery around it. The insertion rule is Watson’s, and the implementation names it in its own comments: a new point deletes every triangle whose circumcircle contains it, and the cavity is refilled by joining the new point to each edge of the cavity’s rim. The structure starts as one triangle large enough to hold everything, and that triangle’s own vertices are removed at the end. Bowyer published the same rule independently the same year, in the same issue of the same journal, which is why the literature usually hyphenates the two names.

It is not a mesh generator. It takes a point set decided elsewhere and connects it, without asking whether the point set was a good one. This is why the lattice rules of the last section matter so much: nothing downstream questions the point set, so nothing downstream repairs a bad one.

The best-known tool of the other kind is Shewchuk’s Triangle, a two-dimensional quality mesh generator. Given a boundary and a quality target, it inserts points of its own (Chew’s refinement by default, Ruppert’s on request) until the triangles satisfy an angle bound, and it uses adaptive-precision predicates that make the in-circle test exact. Python geometry libraries reach it through a wrapper. A mesher designed around such a generator would not need a lattice at all: it would hand over the boundary and a quality target and let the refinement place the interior points.

A kernel does not do this for two reasons, and only one of them is technical. The technical reason is control. Closed-form placement from the surface’s own radii is a single pass, predictable in cost, trivially parallel across faces, and aimed at what the caller asked for: a deflection is a promise about distance from the surface, an angle bound is a promise about triangle shape, and meeting the second does not establish the first. The other reason is that Triangle’s terms of use say it may not be sold or included in commercial products without a licence from its author, which settles the question for a commercial kernel (the predicates alone are in the public domain; the generator is not). The alternative back end this kernel does carry is Delabella, an MIT-licensed Delaunay triangulator selectable at run time through an environment variable. It computes the same unconstrained triangulation by a different route, and the same constraint pass then runs over its result.

What the triangulation guarantees

The interior is built by Delaunay insertion, but the result does not have every property the name implies. We need to know where it falls short before relying on it.

The property that makes a Delaunay triangulation useful is the empty-circumcircle condition: no vertex lies inside the circumcircle of any triangle. It makes the triangles as close to equilateral as the point set allows, and it is why downstream consumers prefer one. Here it holds in the interior of a face, but not near the boundary.

The reason is how a violated constraint is recovered. The boundary polygon must appear in the mesh as actual links, and after insertion some triangles cross it. Recovery deletes those triangles, walks the free links this exposes to rebuild the polygon on the material side, and fills that polygon greedily, joining the closest available pair again and again. The fill has no empty-circle property, and nothing runs afterwards to restore one. So along every constraint, which means along every edge of the model, the triangles are whatever the fill produced.

The second limitation is that the predicates are not exact. The in-circle test is a floating-point comparison against a tolerance, and a package can carry two of them that disagree. The result is held together by repair: the cavity a new point opens grows only through triangles connected to the first one, so an inconsistent predicate elsewhere cannot punch a hole; insertions that produce an invalid state are rolled back; a cleanup sweep runs to a fixpoint afterwards; and the constraint pass gets a second attempt and then a retry.

This is the same choice part seven, section three, described from the other side, and it is an understandable position for a thirty-year-old kernel. The exact-arithmetic alternative (adaptive-precision predicates that compute only as many digits as the sign needs) would remove this whole category of failure, but it would also mean rewriting every predicate in the package. It is the right choice for a kernel started now. Without it, an old mesher relies on a series of recoveries instead of a proof.

Seams and poles

The parameter rectangle of a closed surface is not a faithful chart of it. It fails in two places, and both have to be handled before any triangle is built.

The seam. On a cylinder, a sphere or a torus, the left and right edges of the rectangle are the same curve on the surface. The face’s boundary leaves at one side and returns at the other, so a loop that is closed in space is open in the chart. The fix is an artificial edge along the seam, carrying two pcurves for one curve, one at each end of the rectangle. Both get their points from the same three-dimensional tessellation of the edge, computed as in part eight, so the two sides of the rectangle carry the same number of nodes at the same heights. Only one of the two can constrain the triangulation, since the region is on one side of it; the other is read back afterwards, so that the polygon recorded for that edge refers to real nodes of the mesh.

The pole. The top edge of a sphere’s rectangle is a full-width segment at v = π/2, and every point of it is the same point in space. It is a real edge of the topology with zero length in space and full width in the chart (a degenerate edge), and it exists so that the parameter rectangle closes: without it the region is not bounded and the polygon does not close. Its own tessellation is discarded, because interpolating between two parameters that map to the same point produces nothing; only its ends are kept. The result is the fan of triangles around each pole, all sharing one vertex, and all as thin as the crowding at the top of the rectangle in the figure implies.

These are the same two structures part seven met, for the same reason. A seam edge is more than bookkeeping about periodicity: it is a topological device, introduced because an algorithm needs an edge there to hit.

A trimmed face from a real model

So far we have worked on primitives: a whole sphere, a whole cylinder, a torus with nothing cut out of it. Real faces are trimmed, and this is where the previous sections come together.

The face below is one of 235 in a part from a public archive of engineering models. Its surface is a sphere of radius 7000. Its boundary is not the edge of the rectangle: the outer wire steps in and out twice, and twelve inner wires punch holes of four different kinds through the middle of it. None of this changes the lattice. The rule looks at the surface, not at the trimming, and lays down the same evenly spaced, row-staggered grid it would lay over an untrimmed sphere.

u v π 2π −π/2 π/2 the parameter rectangle the face DETAIL: ONE HOLE, AT 5× THE SCALE the edge stage’s points, and the lattice’s, as nodes of one triangulation the boundary went in first, as constraints; the lattice was inserted into the result one point at a time WHAT THE TRIANGULATOR WAS HANDED 414 points from the edges placed before any face was touched 60 lattice points kept inside the face, and used 6 fall outside it in a hole, or past the trimmed edge 474 nodes in one triangulation 2 more lattice points vetoed for crowding a boundary node face 198 of 235, deflection 300
One face of a real part, with both halves of part eight applied to it at once. The face is a hemisphere carrying twelve holes and an outer boundary that steps in and out of the rectangle twice; in space it is one of 235 faces of a model from a public archive. The lattice is laid over the rectangle as if none of that were there: 68 points, one rule, evenly spaced in both directions and staggered row against row. Each point is then asked the question of part seven (is this point inside the face?), and 6 of them are not, because they fall in a hole or past the trimmed edge; 2 more are dropped for sitting too close to a node the boundary already placed. The remaining 60 become vertices. The test is a ray cast against the polygons drawn here, which are the boundary as the mesher sees it: chains of straight segments in a plane, not curves in space. Those chains are the second half of the answer, and the detail panel is there because at full size they cannot be told apart from solid lines: 414 of the 474 nodes in this face came from the edge stage, before the face was looked at, and only 60 from the lattice. In the magnified hole the two kinds of point are the same kind of thing, corners of the same triangles, because the boundary went in first, as constraints the triangulator may not move, and the lattice was then inserted into the result one point at a time.

Each of these points is then asked the question of part seven. Sixty-eight are laid down; six of them fall in a hole or past the trimmed edge and are discarded; two more are dropped for sitting closer to a boundary node than the minimum size allows; sixty become vertices. This is the over-generate-and-reject of section three, on a face where we can count it.

This face also makes the argument of section one concrete. The test is a ray cast against the polygons drawn in the rectangle: straight segments in a plane, with each crossing decided by the sign of a small determinant. The same question asked in space would need a path across a curved surface and a curve-on-surface intersection at every crossing, and the points would have to be projected back to parameters before the boundary could be consulted at all. So the saving is more than a constant factor on a cheap operation: it replaces a numerical solve with an arithmetic test, once per candidate point, on every face of the model.

The routine itself is part seven’s, unchanged: parity from a ray cast against the chord polygon of each loop, one loop at a time, with the loops’ roles combining the separate answers into one.

It differs in one visible detail. The face classifier labels a loop outer or inner by the sign of the area it encloses. The mesher’s copy instead accumulates the turning angle around the loop (the sum of the angles between consecutive segments, skipping near-straight and near-reversed ones) and calls the loop outer if the total is positive. The two agree on any well-formed loop. They differ on a loop that crosses itself, where the turning angles cancel out and the angle method has to choose; it calls such a loop outer, which is the conservative answer, because treating a broken loop as a hole would delete material.

Two classifiers for one problem in one codebase are typical of a kernel this old. The mesher is also where the preprocessing part seven mentioned pays off: a grid built lazily over a boundary, only once that boundary has been queried enough times, suits this caller well. A Boolean asks a few questions of a boundary it is about to discard; a mesher asks thousands of questions of a boundary that does not change.

Predicted and measured deflection

Everything so far is prediction. The lattice was computed from radii and a formula, and no triangle was compared against the surface it approximates. Whether the prediction holds is a separate question.

Checking it means measuring, and the measurement is local and cheap. Let’s take one triangle. Its three vertices lie on the surface; its interior does not. We take the centroid of its three parameter points, evaluate the surface there to get the point the triangle should pass through, and measure the distance from that point to the triangle’s plane. That is the deviation. We do the same for the midpoint of each of its links, against the line instead of the plane. If the worst of these exceeds the deflection, we insert a point there and retriangulate, and we repeat until a pass proposes nothing new or a fixed number of passes is spent.

The loop has three refinements, each handling a real failure mode:

  • Boundary links are skipped. A frontier link is shared with the neighbouring face, and refining it would break the invariant described in part eight’s fourth section. The boundary is fixed before this loop starts and stays fixed.
  • The minimum size vetoes insertions, and the veto is a spatial query instead of a comparison: the candidate point is looked up against the existing nodes near it, and rejected if it is closer to one than the floor allows. A deflection test that could not be vetoed would loop forever on a sliver.
  • The angle criterion can overrule the length test in the other direction. If the surface normals at the two ends of a link differ by more than the allowed angle, a point goes in even though the distance test passed. This is the only place the angular parameter reaches the interior of a face, and it catches a region that is flat overall but turns sharply over a short distance.

Let’s compare this with what part eight found on the edges. A walked curve places its points by prediction and then checks them, at the midpoint of every span, against both the distance and the angle, and the step is shrunk until the measurement passes. The same kernel, one stage later, places the interior of an analytic face by prediction and checks nothing. The check exists in the codebase, but not on this path.

This matters for anyone relying on the number. That loop is commonly not run on analytic surfaces. The setting that enables it is on by default and is read by the free-form path; the elementary surfaces use it only under a second, separate flag. For a sphere, a cone or a torus, the closed-form lattice is therefore the whole interior strategy, and it is open-loop: the formula is applied and the result is never checked.

The prediction misses, in the expected direction. A sphere of radius 10 asked for a deflection of 0.01 measures 0.017. Turning the loop on brings it to 0.014 and costs forty-two per cent more triangles. Neither number is a disaster, and neither is the number requested: a caller who set 0.01 because a downstream tolerance was 0.015 has been let down without being told. The constant below one in the sphere’s step is the compensation: a factor standing in for a measurement, tuned once and applied always.

This is the same kind of decision as in part seven, made the other way. There, a cheap test was allowed to say it did not know, and an expensive one ran for the cases it declined. Here a cheap prediction is delivered as if it were a measurement, and the caller is not told. The formula itself is good, and on a cylinder it is exact. But a prediction and a measurement are different kinds of claim, and a deflection is a promise about geometry that only a measurement can check.

Checklist for building a face mesher

In the order the decisions have to be made, because several of them are hard to revisit.

  • Tessellate shared curves once, upstream of the faces. Conformance comes by construction, never by merging afterwards. The rest of the design follows from this, and retrofitting it means rewriting the pipeline.
  • Hold the boundary tighter than the interior, and never move it afterwards. An error on a shared edge cannot be corrected by either of the faces that share it.
  • Decide whether you are writing a triangulator or a mesh generator, and say which. A triangulator connects a point set somebody else chose; a generator inserts points of its own until a quality bound is met. The first needs the surface rules of section two to be right, because nothing later will correct them. The second needs a quality target the caller understands, which a deflection is not.
  • Re-check the boundary polygon in the parameter plane as well as in space. The triangulator sees straight segments between consecutive points of the rectangle, and on a curved surface those are not the edge. An edge that meets its deflection in space can still be wrong as a polygon on the face.
  • Derive the step from the relation instead of a table. Radius and deflection give the step; the angular ceiling and the minimum size are the two places the relation is overruled, and they should be the caller’s numbers instead of constants in your code.
  • Treat a ruled direction as free. Wherever the surface is exactly straight there is no deflection to correct, and interior points placed there are wasted. Then account for what this gives up, and add a length criterion if your callers need shape as well as accuracy.
  • Push anisotropy into the coordinates. Scaling the parameter space before triangulating lets an algorithm that knows nothing about the metric produce well-shaped triangles anyway. This is cheaper than changing the algorithm.
  • Measure the deflection achieved and report it. A prediction does not show that the deflection was met. If the measurement loop is too expensive to run always, make that a choice the caller makes knowingly, and write the achieved value back where they can read it.
  • Make the minimum size a hard veto. Every refinement loop needs a reason to stop that does not depend on the geometry being well behaved.
  • Handle the seam and the degenerate edge before the mesher starts, not inside it. Code that handles periodicity and triangulation at the same time is hard to read and maintain.
  • Know what your triangulation does not guarantee. If the empty-circle property fails along the constraints, say so, because a downstream consumer that assumed it will find out at a high cost.

The test set that finds the bugs. A full sphere, for the poles and the seam at once. A cylinder whose height is a thousand times its radius, and one whose radius is a thousand times its height, for aspect ratio. A torus thin enough that the two radii differ by two orders of magnitude. A face with a hole whose boundary comes within a minimum size of the outer loop. A fillet whose radius is below the minimum size. Two faces meeting at an edge whose stored parametrisation is not the curve’s own. A face whose deflection request is below twice the tolerance of the geometry it sits on: the request will be silently raised, and this is the usual reason a dirty imported model will not mesh as finely as asked. For every one of them, assert the achieved deflection instead of the triangle count, because the count is a fact about your implementation and the deflection is the promise made to the caller.

What this leaves out

Quadrilateral and quad-dominant meshing, which is what a simulation caller often wants, and which is a different algorithm, not a post-processing step on this one.

Curvature-adapted sizing beyond the two clamps: sizing fields, gradation control, and the machinery for asking that triangle size vary smoothly across a face instead of jumping where two surface types meet.

Meshing an assembly to a shared budget, where the deflection is relative to the size of the whole instead of each part, and where two parts that touch must agree across the contact.

And remeshing: taking a triangulation that already exists, from an import or an earlier session, and improving it without the surface it came from. Everything above assumes the exact geometry is still available to query.

Reading list

Sources

A. Bowyer, “Computing Dirichlet tessellations”, The Computer Journal 24 (2), 1981, 162–166, and D. F. Watson, “Computing the n-dimensional Delaunay tessellation with application to Voronoi polytopes”, same issue, 167–172. Not consulted directly. The insertion kernel described in section three is the algorithm these two papers introduced independently, and the implementation studied for this article names them in its own comments. The account here is of the code, not of the papers.

J. R. Shewchuk, Triangle: a two-dimensional quality mesh generator and Delaunay triangulator, cs.cmu.edu/~quake/triangle.html (opens in a new tab), read directly. The source for what section three says about refinement to an angle bound, about Chew’s algorithm being the default and Ruppert’s the option, about the predicates being separately in the public domain, and about the terms under which the generator itself may be used. The Python wrapper drufat/triangle (opens in a new tab) is how Python code usually calls it.

J. R. Shewchuk, “Adaptive precision floating-point arithmetic and fast robust geometric predicates”, Discrete & Computational Geometry 18 (3), 1997, 305–363. Not consulted directly. Cited for the alternative section four describes, not for anything asserted about it; the bibliographic record was checked and the paper was not read.

M. Sokalski, Delabella: the MIT-licensed Delaunay triangulator carried as a second back end, named here from the licence header and the selection code, not from its own documentation.

The example face in section six is from the NIST engineering design models (opens in a new tab) archive, a public collection of CAD parts contributed for interoperability benchmarking. It was chosen by search: every analytic face in some eleven thousand model files on hand was scored for having both inner contours and an outer wire that is not a rectangle, and this one scored highest.

Method

The two lattice figures are not drawings. The triangulations in them were produced by meshing a sphere, a cylinder, a cone and a torus through a production kernel at one deflection, dumping the parameter-space nodes, the space nodes and the triangles, and replaying them. So the interior node counts quoted in the captions are counts of what is on the page, and the empty rectangle is a real empty result.

The figure in section six is also a dump. The part was meshed whole, at a deflection of 300 on a sphere of radius 7000, chosen so that the lattice is countable on the page; the rows and the spacing drawn are read back from the interior nodes the mesher kept, not recomputed from the rule, and each point’s verdict is the kernel’s own face classifier, called on that point. The counts in the caption and in the prose (68 laid down, 6 outside, 2 vetoed, 60 used) are counts of that run, and the script asserts that no point the mesher used is one the classifier rejects.

The numbers in section seven were measured by meshing a sphere of radius 10 at a requested deflection of 0.01 and computing, for every triangle, the distance from its plane to the surface point at its own parametric centroid. The figure of 0.017 is that maximum with the refinement loop in its default state, 0.014 with it enabled for analytic surfaces, and the triangle counts behind the forty-two per cent are 10,108 and 14,394. It is a lower bound in both cases, since sampling the centroid alone cannot find a worse point elsewhere in the triangle.

The costs quoted in section one were timed on the same machine, over four hundred random parameter pairs per surface, as the mean of many runs: evaluating the surface at a parameter pair against recovering the parameters of the point that came back. On a sphere, 0.73 µs out against 3.73 µs back, or 0.81 µs using the closed-form inverse; on two free-form faces from other models, 1.7 µs out against 6.4 ms back and 1.2 µs against 39 ms, falling to 27 µs and 335 µs when the search is handed a starting guess one per cent of the domain away from the answer. The claim that a point in space is classified by first recovering its parameters was read in the source, not inferred from the timings.

The claim that the same function serves the circular edge and the spherical lattice was established the same way, and then checked against a measurement: on a sphere of radius 7000 at a deflection of 300, the relation returns 0.587 rad, the angular ceiling cuts it to 0.5, the lattice factor of 0.7 takes it to 0.35, and the range of π divided by a whole number of those gives 0.34907, which is the row spacing the dump in part nine came back with, to five decimal places.

The behaviours described generically throughout (the per-surface-type lattices and their staggering, coupling and scaling; the empty lattice on planes and cylinders; the single upstream tessellation of a shared curve; the skipping of frontier links during refinement) were each read in the source of one production kernel. They are stated here without attribution because this series is about the problem rather than any one implementation of it.

Revision history

. Part numbers renumbered for the new part two, The Mathematics a Kernel Stands On.