Algorithm Search⌘K

Algorithmresearch

Sliver exudation

Also called Cheng-Dey-Edelsbrunner sliver removal.

Removes slivers from a Delaunay tetrahedral mesh by giving each vertex a small weight, so that the weighted Delaunay triangulation of the same points avoids them.

Time
O(n) worst
Space
O(n) extra
Where
n = the number of vertices
Properties
deterministicexactiterative
Origin
Siu Wing Cheng, Tamal K. Dey, Herbert Edelsbrunner, Michael A. Facello, Shang Hua Teng, 1999

Sliver exudation removes slivers from a Delaunay tetrahedral mesh without moving any vertex or adding one. It gives each vertex pp a weight P2P^2, the squared radius of a small sphere around pp, and replaces the Delaunay triangulation by the weighted Delaunay (regular) triangulation of the same points. Cheng, Dey, Edelsbrunner, Facello and Teng proved that if the Delaunay mesh has bounded radius-edge ratio, as tetrahedral Delaunay refinement produces, then weights exist that make every tetrahedron fat, and the weights can be found one vertex at a time. The proof gives a positive constant that the authors call "miserably tiny", while in practice the method raises the smallest dihedral angle to about 5°5°.

In plain words

A Delaunay mesh with good radius-edge ratios can still contain slivers: flat tetrahedra whose four vertices lie near a circle. A sliver is fragile. If one of its vertices gets a weight, its orthosphere (the sphere that is orthogonal to the four weighted spheres) moves, and some other vertex falls inside it, so the sliver leaves the triangulation. Sliver exudation visits each vertex once. It removes the vertex, looks at the finitely many weights at which the triangulation around it changes, tries one weight between each pair, and keeps the weight whose star has the largest smallest dihedral angle. The weight stays below (0.45 d)2(0.45\, d)^2, where dd is the distance to the nearest other vertex, so the spheres stay disjoint and no vertex disappears.

The problem

The input is a finite point set SS in R3\mathbb{R}^3 whose Delaunay triangulation Del S\mathrm{Del}\, S has the Ratio Property [ρ0][\rho_0]: every tetrahedron has circumradius RR and shortest edge LL with R/L≤ρ0R / L \le \rho_0. The output is a weight wp=P2≥0w_p = P^2 \ge 0 for each point pp, and the weighted Delaunay triangulation of the weighted points, chosen so that no tetrahedron is a sliver.

Two weighted points (p,wp)(p, w_p) and (x,wx)(x, w_x) have power distance π=∣p−x∣2−wp−wx\pi = |p - x|^2 - w_p - w_x. Four weighted points in general position have a unique orthosphere (z,Z2)(z, Z^2) with ∣p−z∣2−Z2=wp|p - z|^2 - Z^2 = w_p for each of them; with zero weights it is the circumsphere. A weighted point (e,we)(e, w_e) conflicts with the tetrahedron if its power distance to the orthosphere is negative. The weighted Delaunay triangulation has a tetrahedron on four weighted points exactly when no other weighted point conflicts with it. Its sizes are measured, as in the paper, by Σ=V/L3\Sigma = V / L^3, the volume over the cube of the shortest edge. A tetrahedron is a sliver when Σ\Sigma is small though its ratio is bounded.

The weights must satisfy the Weight Property [Ω0][\Omega_0] for a constant Ω0∈(0,12)\Omega_0 \in (0, \frac12): for every two points p,qp, q, 0≤P≤Ω0∣p−q∣0 \le P \le \Omega_0 |p - q|. Then the spheres are disjoint, and every point remains a vertex.

This page makes three kinds of claim.

  • Existence theorem, cited. The Sliver Theorem (Section 6.5 of the paper): "Assume Del S has Ratio Property [ρ0][\rho_0]. Then there is a constant Σ0>0\Sigma_0 > 0 and a weight assignment defining a set of spheres with Weight Property [Ω0][\Omega_0] such that Σ>Σ0\Sigma > \Sigma_0 for all tetrahedra pqrs" of the weighted Delaunay triangulation. The theorem is stated for periodic point sets S=S0+Z3S = S_0 + \mathbb{Z}^3, which have no boundary. The paper gives no number for Σ0\Sigma_0; its Section 8.1 says "the estimate for Σ0\Sigma_0 provided by the Sliver Theorem is miserably tiny" and leaves open how it depends on ρ0\rho_0 and Ω0\Omega_0. Claim 7 (Section 5.1) adds that the weighted triangulation has orthoradius over shortest edge Z/L≤ρ1Z / L \le \rho_1 for a constant ρ1\rho_1 that depends only on ρ0\rho_0 and Ω0\Omega_0, also without a number.
  • Proved here. The power test that the implementation uses, and the fact that pumping never lowers the smallest dihedral angle of the mesh. Also a lemma that turns the theorem into a dihedral angle bound with explicit dependence: every dihedral angle θ\theta of the weighted triangulation of the theorem satisfies sin⁡θ≥Σ0(1−4Ω02)2/(2ρ14)\sin\theta \ge \Sigma_0 (1 - 4\Omega_0^2)^2 / (2\rho_1^4). For Ω0=0.45\Omega_0 = 0.45 the factor (1−4Ω02)2/2(1 - 4\Omega_0^2)^2/2 is 0.0180.018, so the bound is a tiny multiple of a tiny constant. See proofs/correctness.md.
  • Measured, no guarantee. Edelsbrunner and Guoy write that the proved constant is "positive but miserably small" and that the constant reached in practice is "much larger and possibly around 5°". On a mesh of more than 76,000 tetrahedra they moved every dihedral angle above 5°5° except one, which was above 3°3°, next to the boundary. Labelle and Shewchuk note that the provable bounds of Delaunay methods with sliver removal are below 0.1°0.1° and probably below a millionth of a degree. In the example below the smallest angle rises from 0.14°0.14° to 5.20°5.20°.

A radius-edge bound alone does not remove slivers: a sliver can have R/LR / L as low as 1/21/\sqrt2. That is why sliver exudation exists, and why it needs the Ratio Property only as a hypothesis, not as the goal.

The algorithm

Fix the weights of all vertices except uu, and let TuT_u be the weighted Delaunay triangulation without uu. For each tetrahedron tt of TuT_u the critical weight wtw_t is the power distance from uu (at weight 00) to the orthosphere of tt. The weighted point (u,w)(u, w) conflicts with tt exactly when w>wtw > w_t. So the triangulation with uu at weight ww is TuT_u with the tetrahedra {t:wt<w}\{t : w_t < w\} removed and uu joined to the boundary of the hole, and it changes only when ww crosses a critical weight.

  1. SLIVER-EXUDATION(S, Ω0)
  2. 1T ← the Delaunay triangulation of S; every weight is 0
  3. 2for each vertex u, once, in any order:
  4. 3T_u ← the weighted Delaunay triangulation of S without u
  5. 4for each tetrahedron t of T_u: w_t ← power distance from (u, 0) to the orthosphere of t
  6. 5W ← (Ω0 d_u)^2, where d_u is the distance from u to its nearest other point
  7. 6candidates ← 0 and one weight strictly between each two consecutive critical weights in [0, W]
  8. 7for each candidate w: star(w) ← u joined to the boundary of {t in T_u : w_t < w}; ζ(w) ← its smallest dihedral angle
  9. 8w* ← the candidate of largest ζ, keeping 0 on ties
  10. 9w_u ← w*; T ← (T_u minus the removed tetrahedra) plus star(w*)
  11. 10return T and the weights
  12. 11conflict test: (e, w_e) conflicts with abcd iff -det[p - e, |p - e|^2 - w_p + w_e] (rows p = a, b, c, d) has the sign of orient3d(a, b, c, d)

The test of L11 is the weighted form of the insphere test: with all weights 00 it is the insphere determinant. The paper's own rule (Section 7.1) picks the weight that maximizes the smallest Σ\Sigma in the star; Edelsbrunner and Guoy's implementation, and this one, maximize the smallest dihedral angle instead. Edelsbrunner and Guoy evaluate the star at each critical weight as it grows; here a weight strictly between two critical weights is used, so no four weighted points are ever on a common orthosphere.

The paper treats periodic sets. The implementation puts the points in a box whose 8 corners are part of the input and keep weight 00; only the points strictly inside are pumped. Coordinates and weights are integers, so every orientation and power test is exact integer arithmetic, and the critical weights are exact fractions. L3 rebuilds the triangulation without uu by Bowyer-Watson insertion with the power test.

Example

The input is 27 points near the grid points (i,j,k)⋅1000(i, j, k) \cdot 1000 for i,j,k∈{1,2,3}i, j, k \in \{1, 2, 3\}, each coordinate moved by a random integer in [−100,100][-100, 100] (seed 2), inside the box [0,4000]3[0, 4000]^3, with Ω0=0.45\Omega_0 = 0.45. The steps come from the implementation, and the test file checks them.

Step Vertex What happens
L1 35 vertices, 151 tetrahedra; smallest dihedral angle 0.14°0.14°, 9 tetrahedra below 5°5° and 17 below 10°10°
the worst is a sliver on (3034,1095,993)(3034, 1095, 993), (3051,990,1992)(3051, 990, 1992), (3002,2083,1089)(3002, 2083, 1089), (3018,2067,2035)(3018, 2067, 2035), with angles 0.14°0.14° and 179.78°179.78° and radius-edge ratio 2.902.90
pump 2 (992,943,2088)(992, 943, 2088) weight 138757138757 of at most 156905156905; the smallest angle in its star rises from 3.10°3.10° to 4.77°4.77°
pump 7 (1000,3085,1030)(1000, 3085, 1030) weight 183429183429; star from 5.20°5.20° to 22.30°22.30°
pump 19 (3034,1095,993)(3034, 1095, 993) weight 4484544845 of at most 199742199742; star from 0.14°0.14° to 5.47°5.47°; the worst sliver is gone and the mesh minimum rises to 3.02°3.02°
pump 23 (3018,2067,2035)(3018, 2067, 2035) weight 103673103673, chosen among 14 candidates; star from 3.02°3.02° to 16.74°16.74°; the mesh minimum rises to 5.20°5.20°
end 139 tetrahedra; smallest angle 5.20°5.20°, none below 5°5° and 6 below 10°10°; 11 of the 27 points got a positive weight, the largest with P/du=0.435P / d_u = 0.435

Sixteen of the 27 pumps keep weight 00, because no weight improves their star. The number of tetrahedra drops, as Edelsbrunner and Guoy also observe, because a sliver and its neighbors are replaced by fewer tetrahedra. With seed 1 and moves up to 150150, the minimum rises from 1.54°1.54° to 3.03°3.03°, and the worst remaining tetrahedron has a box corner as a vertex, which is never pumped: near the boundary the method has little room, as the paper's boundary-free setting suggests.

Correctness

The power test. Lift each weighted point to p+=(p,∣p∣2−wp)p^+ = (p, |p|^2 - w_p) in R4\mathbb{R}^4. The four lifted vertices of a tetrahedron lie on the graph of an affine function h(x)=2z⋅x−∣z∣2+Z2h(x) = 2 z \cdot x - |z|^2 + Z^2, where (z,Z2)(z, Z^2) is the orthosphere, and the power distance of (e,we)(e, w_e) to the orthosphere is ∣e∣2−we−h(e)|e|^2 - w_e - h(e). Column operations turn the determinant of L11 into π\pi times orient3d(a,b,c,d)\mathrm{orient3d}(a, b, c, d), so the test returns −π ∣orient3d∣-\pi\, |\mathrm{orient3d}|, positive exactly in conflict. The full proof is in proofs/correctness.md, and the tests compare the test with an orthosphere computed by exact Gaussian elimination on 300 random weighted configurations.

Each pump keeps the triangulation regular. By the lifting, the weighted Delaunay triangulation is the projection of the lower convex hull of the lifted points, and adding (u,w)(u, w) removes exactly the facets whose hyperplane passes above u+u^+, which are the tetrahedra with wt<ww_t < w, and cones uu to the horizon. The tests check that the final mesh has no conflict between any tetrahedron and any weighted point, that the volumes sum to the box, and that it equals a triangulation rebuilt from scratch with the final weights.

The smallest dihedral angle never decreases. Weight 00 is always a candidate, and at weight 00 the star is the current star of uu. A larger weight only removes more tetrahedra of TuT_u. So the new mesh consists of tetrahedra of the old mesh and the new star, whose smallest angle is at least that of the old star. The tests check this after every pump.

The guarantee. The Sliver Theorem is cited, not proved here. Its proof shows that for each vertex the weights at which the star contains a sliver cover only part of the interval [0,(Ω0du)2][0, (\Omega_0 d_u)^2], and picks a weight outside them; the Ratio Property bounds how many tetrahedra can ever appear in the star. The bound sin⁡θ≥8Σ/λ4\sin\theta \ge 8\Sigma / \lambda^4, with λ\lambda the longest over the shortest edge, and λ≤2ρ1/1−4Ω02\lambda \le 2\rho_1 / \sqrt{1 - 4\Omega_0^2} under the Weight Property, are proved in proofs/correctness.md and checked on every tetrahedron of the tests.

Proof: The power test is exact, pumping keeps the triangulation regular and never lowers the smallest dihedral angle, and the Sliver Theorem gives a dihedral angle boundfull

Claim. Assume general position: no five lifted weighted points lie on a common hyperplane, and no candidate weight equals a critical weight.

  1. The test of L11 returns −π ∣orient3d(a,b,c,d)∣-\pi\, |\mathrm{orient3d}(a, b, c, d)|, where π\pi is the power distance from (e,we)(e, w_e) to the orthosphere of the four weighted points a,b,c,da, b, c, d. So it is positive exactly when (e,we)(e, w_e) conflicts with the tetrahedron, and with all weights 00 it is the insphere test. The critical weight of L4 is the power distance from (u,0)(u, 0) to the orthosphere, and (u,w)(u, w) conflicts with tt exactly when w>wtw > w_t.
  2. For each weight ww, the set (Tu∖{t:wt<w})∪star(w)(T_u \setminus \{t : w_t < w\}) \cup \mathrm{star}(w) is the weighted Delaunay triangulation with uu at weight ww, as long as (u,w)(u, w) is a vertex of it.
  3. The smallest dihedral angle of the mesh after the pump of L9 is at least the one before.
  4. Every tetrahedron with shortest edge LL, longest edge DD and volume VV has every dihedral angle θ\theta with sin⁡θ≥8Σ/λ4\sin\theta \ge 8\Sigma / \lambda^4, where Σ=V/L3\Sigma = V / L^3 and λ=D/L\lambda = D / L.
  5. If the weights have the Weight Property [Ω0][\Omega_0], every tetrahedron of the weighted Delaunay triangulation with orthoradius ZZ has D2(1−4Ω02)≤4Z2D^2 (1 - 4\Omega_0^2) \le 4 Z^2.
  6. Hence, for the weights of the Sliver Theorem, every dihedral angle of the weighted Delaunay triangulation satisfies sin⁡θ≥Σ0(1−4Ω02)2/(2ρ14)\sin\theta \ge \Sigma_0 (1 - 4\Omega_0^2)^2 / (2 \rho_1^4).

What is cited. Part 6 uses the Sliver Theorem (Section 6.5 of Cheng, Dey, Edelsbrunner, Facello and Teng, J. ACM 2000), which gives Σ>Σ0\Sigma > \Sigma_0, and their Claim 7 (Section 5.1), which gives Z/L≤ρ1Z / L \le \rho_1; neither proof is repeated, and the paper gives no number for Σ0\Sigma_0 or ρ1\rho_1. Part 2 uses the standard fact that the weighted Delaunay triangulation is the projection of the lower convex hull of the lifted points (Chapter 7 of Cheng, Dey and Shewchuk) and the beneath-beyond rule for adding a point to a convex hull. The fact that every point stays a vertex under the Weight Property is from the paper (Section 4.2).

Step 1: the lifting. Lift a weighted point (p,wp)(p, w_p) to p+=(p,ℓp)p^+ = (p, \ell_p) in R4\mathbb{R}^4 with ℓp=∣p∣2−wp\ell_p = |p|^2 - w_p. The orthosphere (z,Z2)(z, Z^2) of a,b,c,da, b, c, d satisfies ∣p−z∣2−Z2=wp|p - z|^2 - Z^2 = w_p, which expands to ℓp=2z⋅p−∣z∣2+Z2\ell_p = 2 z \cdot p - |z|^2 + Z^2. So the four lifted points lie on the graph of the affine function h(x)=2z⋅x−∣z∣2+Z2h(x) = 2 z \cdot x - |z|^2 + Z^2. For any weighted point (e,we)(e, w_e),

∣e−z∣2−Z2−we=ℓe−h(e),|e - z|^2 - Z^2 - w_e = \ell_e - h(e),

so the power distance π\pi of (e,we)(e, w_e) to the orthosphere is the height of e+e^+ above that graph. Conflict, π<0\pi < 0, means that e+e^+ lies below the hyperplane through a+,b+,c+,d+a^+, b^+, c^+, d^+.

Step 2: the determinant (part 1). Let MM be the 4×44 \times 4 matrix with rows (p−e, ∣p−e∣2−wp+we)(p - e,\ |p - e|^2 - w_p + w_e) for p=a,b,c,dp = a, b, c, d. Since

∣p−e∣2−wp+we=(ℓp−ℓe)−2e⋅(p−e),|p - e|^2 - w_p + w_e = (\ell_p - \ell_e) - 2 e \cdot (p - e),

subtracting 2ek2 e_k times column kk from column 4, for k=1,2,3k = 1, 2, 3, gives rows (p−e, ℓp−ℓe)(p - e,\ \ell_p - \ell_e) with the same determinant. Now ℓp=h(p)\ell_p = h(p) for the four vertices, and h(p)−ℓe=2z⋅(p−e)+h(e)−ℓe=2z⋅(p−e)−πh(p) - \ell_e = 2 z \cdot (p - e) + h(e) - \ell_e = 2 z \cdot (p - e) - \pi. Subtracting 2zk2 z_k times column kk from column 4 gives rows (p−e, −π)(p - e,\ -\pi). Factor out −π-\pi: the determinant of the rows (p−e,1)(p - e, 1) is, after subtracting the first row from the others, the determinant of the rows (a−e,1),(b−a,0),(c−a,0),(d−a,0)(a - e, 1), (b - a, 0), (c - a, 0), (d - a, 0), which by expansion along the last column is −det⁡[b−a,c−a,d−a]=−orient3d(a,b,c,d)-\det[b - a, c - a, d - a] = -\mathrm{orient3d}(a, b, c, d). So

det⁡M=(−π)(−orient3d)=π⋅orient3d(a,b,c,d).\det M = (-\pi)(-\mathrm{orient3d}) = \pi \cdot \mathrm{orient3d}(a, b, c, d).

The implementation returns −det⁡M-\det M times the sign of orient3d, which is −π ∣orient3d∣-\pi\, |\mathrm{orient3d}|: positive exactly when π<0\pi < 0. With all weights 00, MM is the insphere matrix and the orthosphere is the circumsphere. For the critical weight, put we=0w_e = 0: the implementation divides det⁡M\det M by orient3d and gets π0=∣u−z∣2−Z2\pi_0 = |u - z|^2 - Z^2. With weight ww the power distance is π0−w\pi_0 - w, negative exactly when w>π0=wtw > \pi_0 = w_t.

Step 3: the star (part 2). The weighted Delaunay triangulation of a set of weighted points is the vertical projection of the lower convex hull of their lifts, by Step 1: a tetrahedron is in it exactly when no lifted point lies below the hyperplane through its four lifted vertices. Adding the point u+=(u,∣u∣2−w)u^+ = (u, |u|^2 - w) to a lower convex hull removes exactly the facets whose hyperplane passes above u+u^+, the facets visible from below, and joins u+u^+ to the boundary of that region (beneath-beyond). By Step 2 these facets are the tetrahedra tt of TuT_u with wt<ww_t < w. So the new triangulation is TuT_u without them, plus uu joined to the boundary faces of the removed region, which is star(w)\mathrm{star}(w) of L7. If ww is not a critical weight, every wtw_t is either below or above ww, so no tetrahedron is degenerate, and the triangulation is the same for all ww in one open interval between consecutive critical weights. Hence L6 tries every triangulation that a weight in [0,W][0, W] can give, except those at the critical weights themselves.

Step 4: monotonicity (part 3). By induction, before uu is pumped the mesh TT is the weighted Delaunay triangulation with wu=0w_u = 0, because each pump installs the triangulation for the chosen weight (Step 3) and uu has not been pumped yet. Write C(w)={t∈Tu:wt<w}C(w) = \{t \in T_u : w_t < w\}. Then T=(Tu∖C(0))∪star(0)T = (T_u \setminus C(0)) \cup \mathrm{star}(0). Let mm be the smallest dihedral angle of TT; in particular ζ(0)≥m\zeta(0) \ge m, since star(0)⊆T\mathrm{star}(0) \subseteq T. The chosen weight w∗≥0w^* \ge 0 satisfies ζ(w∗)≥ζ(0)\zeta(w^*) \ge \zeta(0) by L8, since 00 is a candidate. Every tt with wt<0w_t < 0 also has wt<w∗w_t < w^*, so C(0)⊆C(w∗)C(0) \subseteq C(w^*) and Tu∖C(w∗)⊆Tu∖C(0)⊆TT_u \setminus C(w^*) \subseteq T_u \setminus C(0) \subseteq T. The new mesh is (Tu∖C(w∗))∪star(w∗)(T_u \setminus C(w^*)) \cup \mathrm{star}(w^*). Its tetrahedra of the first kind belong to TT and have angles at least mm; those of the second kind have angles at least ζ(w∗)≥ζ(0)≥m\zeta(w^*) \ge \zeta(0) \ge m.

Step 5: angle, volume and edges (part 4). Let θ\theta be the dihedral angle at edge ee, between the faces F1F_1 and F2F_2 of areas A1A_1 and A2A_2. The vertex of F2F_2 off ee is at distance 2A2/∣e∣2A_2 / |e| from the line of ee, and at distance (2A2/∣e∣)sin⁡θ(2A_2 / |e|) \sin\theta from the plane of F1F_1. So

V=13A1⋅2A2∣e∣sin⁡θ,sin⁡θ=3V∣e∣2A1A2.V = \frac13 A_1 \cdot \frac{2 A_2}{|e|} \sin\theta, \qquad \sin\theta = \frac{3 V |e|}{2 A_1 A_2}.

A triangle with all sides at most DD has area at most 34D2\frac{\sqrt3}{4} D^2: if cc is its longest side, the third corner is within DD of both ends of cc, so its height over cc is at most D2−c2/4\sqrt{D^2 - c^2/4}, and 12cD2−c2/4\frac12 c \sqrt{D^2 - c^2/4} increases in cc for c≤2Dc \le \sqrt2 D, so it is largest at c=Dc = D. Thus A1A2≤316D4A_1 A_2 \le \frac{3}{16} D^4, and with ∣e∣≥L|e| \ge L,

sin⁡θ≥3VL2⋅316D4=8VLD4=8 (V/L3)(D/L)4=8Σλ4.\sin\theta \ge \frac{3 V L}{2 \cdot \frac{3}{16} D^4} = \frac{8 V L}{D^4} = \frac{8\, (V / L^3)}{(D / L)^4} = \frac{8\Sigma}{\lambda^4}.

Step 6: the Weight Property bounds the longest edge (part 5). Let p,qp, q be vertices of a tetrahedron of the weighted Delaunay triangulation, with orthosphere (z,Z2)(z, Z^2). Then ∣p−z∣2=Z2+wp|p - z|^2 = Z^2 + w_p, and the Weight Property gives wp=P2≤Ω02∣p−q∣2≤Ω02D2w_p = P^2 \le \Omega_0^2 |p - q|^2 \le \Omega_0^2 D^2, and likewise for qq. By the triangle inequality,

∣p−q∣≤∣p−z∣+∣q−z∣≤2Z2+Ω02D2.|p - q| \le |p - z| + |q - z| \le 2 \sqrt{Z^2 + \Omega_0^2 D^2}.

Taking p,qp, q at the ends of the longest edge, D2≤4Z2+4Ω02D2D^2 \le 4 Z^2 + 4 \Omega_0^2 D^2, that is D2(1−4Ω02)≤4Z2D^2 (1 - 4\Omega_0^2) \le 4 Z^2. Since Ω0<12\Omega_0 < \frac12 the left side is positive, so in particular Z2>0Z^2 > 0.

Step 7: the dihedral bound (part 6). Under the hypotheses of the Sliver Theorem, its weights give Σ>Σ0\Sigma > \Sigma_0 for every tetrahedron, and Claim 7 gives Z≤ρ1LZ \le \rho_1 L. By Step 6, λ=D/L≤2ρ1/1−4Ω02\lambda = D / L \le 2 \rho_1 / \sqrt{1 - 4\Omega_0^2}, so λ4≤16ρ14/(1−4Ω02)2\lambda^4 \le 16 \rho_1^4 / (1 - 4\Omega_0^2)^2. By Step 5,

sin⁡θ≥8Σ0(1−4Ω02)216ρ14=Σ0(1−4Ω02)22ρ14.\sin\theta \ge \frac{8 \Sigma_0 (1 - 4\Omega_0^2)^2}{16 \rho_1^4} = \frac{\Sigma_0 (1 - 4\Omega_0^2)^2}{2 \rho_1^4}.

For Ω0=0.45\Omega_0 = 0.45 the factor (1−4Ω02)2/2(1 - 4\Omega_0^2)^2 / 2 equals 0.018050.01805. The bound is positive but inherits the unknown and, by the paper's own account, tiny Σ0\Sigma_0; it is far below the 5°5° seen in practice.

What is not proved. Part 6 is about the weights of the theorem. That the rule of L8, which maximizes the smallest dihedral angle rather than the smallest Σ\Sigma, reaches weights at least as good is not proved here. The implementation also has a boundary, which the theorem excludes. The tests check parts 1 to 5 exactly or to floating point precision on every tetrahedron of two examples. ■\blacksquare

Complexity

Under the Ratio Property the star of every vertex has constant size (Cheng et al.), so a pump looks at a constant number of critical weights and takes constant time once the vertex is located, and the whole method runs in O(n)O(n) time after the Delaunay triangulation is built, as Edelsbrunner and Guoy note. The paper states O(nlog⁡n)O(n \log n) when the triangulation is included. Space is O(n)O(n).

The implementation is simpler: it rebuilds the triangulation without uu from scratch for each pump, with linear scans, so a pump costs O(n2)O(n^2) and the run O(n3)O(n^3). For the 35 points of the example the whole run takes about half a second.

Properties

  • No new vertices, no moved vertices. Only the connectivity changes, through the weights.
  • Monotone. The smallest dihedral angle of the mesh never decreases, and the smallest angle of each pumped star does not decrease either.
  • Every vertex once, in any order. Edelsbrunner and Guoy note that one pass suffices.
  • Existence guarantee, no explicit constant. Σ>Σ0\Sigma > \Sigma_0 for periodic inputs with bounded ratio; the paper does not compute Σ0\Sigma_0.
  • Weak at the boundary. The theorem has no boundary. Edelsbrunner and Guoy name the boundary as the main limitation in practice.
  • Exact here. Integer coordinates and weights; all signs are exact.

Variants and improvements

  • Refinement with pumping. Cheng and Dey (SIAM J. Computing, 2003) mix pumping with Delaunay refinement for polyhedral domains, giving the first deterministic method with boundaries; Chapter 11 of Cheng, Dey and Shewchuk presents it as refinement for sliver exudation.
  • Random perturbation. Chew (1997) and Li and Teng (2001) remove slivers by choosing each new vertex at random in a small region around the circumcenter, with probabilistic arguments and, again, very small constants.
  • Lattice methods. Isosurface stuffing proves dihedral angles of at least 10.78°10.78°, a far better constant, by giving up the Delaunay property and sharp features.
  • Mesh improvement. Topological improvement and optimization-based smoothing have no guarantee but reach 30°30° or more in practice.
  • Weighted features. Protecting balls use the same weighted Delaunay machinery to keep sharp edges in the mesh.

When to use it

Use it as a last step after tetrahedral Delaunay refinement when slivers remain, the vertices must not move, and a weighted Delaunay mesh is acceptable for the solver. It works best in the interior of the domain. If the target is a specific dihedral angle such as 15°15° or more, use mesh improvement instead or after it, because the proved constant gives no such assurance.

Pitfalls

  • Expecting a usable constant. The theorem gives only existence; the measured 5°5° is what to expect.
  • Weights too large. Above Ω0=12\Omega_0 = \frac12 two spheres can overlap and a vertex can become redundant and vanish from the triangulation.
  • Ignoring the boundary. Near the boundary the star is cut off and pumping has few options; Edelsbrunner and Guoy also bound weights so that boundary triangles stay in the mesh.
  • Inexact power tests. The critical weights are close together for a sliver, and a floating point comparison can choose a weight on a critical value, where four weighted points are coplanar in the lifted space.
  • Confusing the measures. The paper's sliver measure Σ\Sigma is a volume ratio, not a dihedral angle; the dihedral bound needs a second step.

Implementations

Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.

mg2geom.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Shared helper of the mg2 cad pages of https://algorithm.tamnd.com/. The authors are listed in prov/.

"""Small exact geometric tools used by the mg2 pages.

Points are tuples of int or fractions.Fraction. Every predicate returns an
exact value when the coordinates are int or Fraction, so its sign is the true
sign. A float converts to a Fraction without rounding (exact()), so the sign
is then exact for the float point as it is stored. The angle functions return
floats and are used only to report or to compare with a stated bound.
"""

import math
from fractions import Fraction
from typing import Sequence, Tuple

Point = Tuple


def exact(p: Point) -> Tuple[Fraction, ...]:
    """The point p with each coordinate converted to Fraction, without rounding."""
    return tuple(Fraction(c) for c in p)


def sub(a: Point, b: Point) -> tuple:
    return tuple(x - y for x, y in zip(a, b))


def dot(a: Point, b: Point):
    return sum(x * y for x, y in zip(a, b))


def cross(a: Point, b: Point) -> tuple:
    return (a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0])


def dist2(a: Point, b: Point):
    return sum((x - y) * (x - y) for x, y in zip(a, b))


def det3(r0: Sequence, r1: Sequence, r2: Sequence):
    return dot(r0, cross(r1, r2))


def det4(m: Sequence[Sequence]):
    """Determinant of a 4 by 4 matrix by cofactor expansion along the first row."""
    total = 0
    for j in range(4):
        minor = [[m[i][k] for k in range(4) if k != j] for i in range(1, 4)]
        term = m[0][j] * det3(minor[0], minor[1], minor[2])
        total += term if j % 2 == 0 else -term
    return total


def orient2d(a: Point, b: Point, c: Point):
    """Twice the signed area of the triangle a, b, c; positive if counterclockwise."""
    return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0])


def orient3d(a: Point, b: Point, c: Point, d: Point):
    """Six times the signed volume of the tetrahedron a, b, c, d.

    It is det[b - a, c - a, d - a]: positive when d lies on the side of the
    plane abc from which a, b, c appear clockwise.
    """
    return det3(sub(b, a), sub(c, a), sub(d, a))


def insphere(a: Point, b: Point, c: Point, d: Point, e: Point):
    """Positive if e lies inside the sphere through a, b, c, d, zero on it.

    The value is det of the rows (p - e, |p - e|^2) for p = a, b, c, d,
    divided by nothing, times the sign of orient3d(a, b, c, d), so the result
    does not depend on the order of a, b, c, d. The tetrahedron must not be flat.
    """
    rows = []
    for p in (a, b, c, d):
        v = sub(p, e)
        rows.append([v[0], v[1], v[2], dot(v, v)])
    o = orient3d(a, b, c, d)
    if o == 0:
        raise ValueError("flat tetrahedron")
    val = -det4(rows)
    return val if o > 0 else -val


def circumcenter3(a: Point, b: Point, c: Point, d: Point) -> tuple:
    """Exact circumcenter of a tetrahedron, by Cramer's rule on 2 (p - a) . x = |p - a|^2."""
    u, v, w = sub(b, a), sub(c, a), sub(d, a)
    det = det3(u, v, w)
    if det == 0:
        raise ValueError("flat tetrahedron")
    bu, bv, bw = Fraction(dot(u, u)), Fraction(dot(v, v)), Fraction(dot(w, w))
    # x = (bu (v x w) + bv (w x u) + bw (u x v)) / (2 det)
    cvw, cwu, cuv = cross(v, w), cross(w, u), cross(u, v)
    x = tuple((bu * cvw[k] + bv * cwu[k] + bw * cuv[k]) / (2 * det) for k in range(3))
    return tuple(a[k] + x[k] for k in range(3))


def tri_circumcenter3(a: Point, b: Point, c: Point) -> tuple:
    """Exact circumcenter of a triangle in space (the center of its smallest circumscribed sphere)."""
    u, v = sub(b, a), sub(c, a)
    n = cross(u, v)
    nn = Fraction(dot(n, n))
    if nn == 0:
        raise ValueError("flat triangle")
    t1 = cross(n, u)
    t2 = cross(v, n)
    uu, vv = dot(u, u), dot(v, v)
    # x = (|u|^2 (v x n) + |v|^2 (n x u)) / (2 |n|^2)
    return tuple(a[k] + (uu * t2[k] + vv * t1[k]) / (2 * nn) for k in range(3))


def radius_edge2(a: Point, b: Point, c: Point, d: Point) -> Fraction:
    """Exact square of the radius-edge ratio R / l_min of a tetrahedron."""
    cc = circumcenter3(a, b, c, d)
    r2 = dist2(cc, a)
    pts = (a, b, c, d)
    lmin2 = min(dist2(pts[i], pts[j]) for i in range(4) for j in range(i + 1, 4))
    return Fraction(r2) / Fraction(lmin2)


def _angle(u: Sequence[float], v: Sequence[float]) -> float:
    nu = math.sqrt(sum(x * x for x in u))
    nv = math.sqrt(sum(x * x for x in v))
    c = sum(x * y for x, y in zip(u, v)) / (nu * nv)
    return math.degrees(math.acos(max(-1.0, min(1.0, c))))


def triangle_angles_deg(a: Point, b: Point, c: Point) -> list:
    """The three plane angles of a triangle in degrees, in 2D or 3D (floats)."""
    p = [tuple(float(x) for x in q) for q in (a, b, c)]
    out = []
    for i in range(3):
        o, s, t = p[i], p[(i + 1) % 3], p[(i + 2) % 3]
        out.append(_angle(sub(s, o), sub(t, o)))
    return out


def dihedral_angles_deg(a: Point, b: Point, c: Point, d: Point) -> list:
    """The six dihedral angles of a tetrahedron in degrees (floats).

    The angle at edge pq is the angle between the two faces pqr and pqs,
    measured inside the tetrahedron.
    """
    p = [tuple(float(x) for x in q) for q in (a, b, c, d)]
    out = []
    for i in range(4):
        for j in range(i + 1, 4):
            k, m = [t for t in range(4) if t not in (i, j)]
            e = sub(p[j], p[i])
            ee = dot(e, e)
            # components of p_k - p_i and p_m - p_i orthogonal to the edge
            u = sub(p[k], p[i])
            v = sub(p[m], p[i])
            u = tuple(u[t] - dot(u, e) / ee * e[t] for t in range(3))
            v = tuple(v[t] - dot(v, e) / ee * e[t] for t in range(3))
            out.append(_angle(u, v))
    return out
sliver_exudation.py 204 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/sliver-exudation/. The authors are listed in prov/4WRSY6.jsonl.

"""Sliver exudation (Cheng, Dey, Edelsbrunner, Facello and Teng, 2000).

Each vertex u in turn is "pumped": its weight (the square U^2 of the radius of
a sphere centered at u) is chosen among the weights for which the weighted
Delaunay (regular) triangulation is free of the worst tetrahedra around u.
The weight is kept at most (OMEGA * d_u)^2, where d_u is the distance from u to
its nearest neighbor and OMEGA < 1/2, so the spheres stay disjoint and every
point stays a vertex. As in Edelsbrunner and Guoy's implementation, the weight
chosen is the one that maximizes the smallest dihedral angle of the star of u.

The paper treats periodic point sets, which have no boundary. Here the points
lie in an axis-aligned box whose 8 corners are part of the input; the corners
keep weight 0, and only the points strictly inside are pumped.

Coordinates and weights are integers, so every power (weighted insphere) test
is exact integer arithmetic. A chosen weight is an integer strictly between two
consecutive critical weights, so no degenerate configuration is ever chosen.
"""

import math
from fractions import Fraction
from typing import Dict, List, Optional, Sequence, Set, Tuple

from mg2geom import det4, dihedral_angles_deg, dist2, orient3d, sub

Tet = Tuple[int, int, int, int]
Face = Tuple[int, int, int]

OMEGA = Fraction(9, 20)  # Edelsbrunner and Guoy use 0.45; any constant in (0, 1/2) is allowed


def power_test(a, b, c, d, e, wa=0, wb=0, wc=0, wd=0, we=0):
    """Positive if the weighted point (e, we) conflicts with the orthosphere of abcd.

    The value is -det of the rows (p - e, |p - e|^2 - w_p + w_e) for p = a, b, c,
    d, times the sign of orient3d(a, b, c, d). It equals -pi * |orient3d|, where
    pi = |e - z|^2 - Z^2 - w_e is the power distance from (e, we) to the
    orthosphere (z, Z^2) of the four weighted points. So it is positive exactly
    when pi < 0, and with all weights 0 it is the ordinary insphere test.
    """
    rows = []
    for p, w in ((a, wa), (b, wb), (c, wc), (d, wd)):
        v = sub(p, e)
        rows.append([v[0], v[1], v[2], v[0] * v[0] + v[1] * v[1] + v[2] * v[2] - w + we])
    o = orient3d(a, b, c, d)
    if o == 0:
        raise ValueError("flat tetrahedron")
    val = -det4(rows)
    return val if o > 0 else -val  # @line L11


def critical_weight(a, b, c, d, u, wa=0, wb=0, wc=0, wd=0) -> Fraction:
    """The power pi_t(u) = |u - z|^2 - Z^2 of the point u to the orthosphere of abcd.

    The weighted point (u, w) conflicts with the tetrahedron exactly when w > pi_t(u).
    """
    rows = []
    for p, w in ((a, wa), (b, wb), (c, wc), (d, wd)):
        v = sub(p, u)
        rows.append([v[0], v[1], v[2], v[0] * v[0] + v[1] * v[1] + v[2] * v[2] - w])
    return Fraction(det4(rows), orient3d(a, b, c, d))


def faces_of(t: Tet) -> List[Face]:
    return [tuple(sorted(t[:i] + t[i + 1 :])) for i in range(4)]


def min_dihedral(pts, tets) -> float:
    return min(min(dihedral_angles_deg(*[pts[v] for v in t])) for t in tets)


class Exuder:
    def __init__(self, side: int, inner: Sequence[Sequence[int]], omega: Fraction = OMEGA):
        if side <= 0:
            raise ValueError("side must be positive")
        self.omega = Fraction(omega)
        if not 0 < self.omega < Fraction(1, 2):
            raise ValueError("omega must lie in (0, 1/2)")
        corners = [(x, y, z) for x in (0, side) for y in (0, side) for z in (0, side)]
        self.pts: List[tuple] = corners + [tuple(int(c) for c in p) for p in inner]
        if len(set(self.pts)) != len(self.pts):
            raise ValueError("repeated point")
        for p in self.pts[8:]:
            if not all(0 < c < side for c in p):
                raise ValueError("inner points must lie strictly inside the box")
        self.side = side
        self.w: List[int] = [0] * len(self.pts)
        self.tets: Set[Tet] = self.triangulate(range(len(self.pts)))  # @line L1
        self.log: List[tuple] = []

    # weighted Delaunay triangulation by Bowyer-Watson insertion with the power test
    def conflicts(self, t: Tet, v: int) -> bool:
        P, W = self.pts, self.w
        return power_test(*[P[x] for x in t], P[v], *[W[x] for x in t], W[v]) > 0

    def triangulate(self, verts) -> Set[Tet]:
        """The regular triangulation of the given vertices with the current weights.

        The 8 corners are always included and start as 6 tetrahedra around the
        diagonal; they are cospherical with equal weights, so this is regular.
        """
        P = self.pts
        tets: Set[Tet] = set()
        face_tets: Dict[Face, Set[Tet]] = {}

        def add(t):
            if orient3d(*[P[x] for x in t]) < 0:
                t = (t[1], t[0], t[2], t[3])
            if orient3d(*[P[x] for x in t]) == 0:
                raise AssertionError("flat tetrahedron: the cavity is not star-shaped")
            tets.add(t)
            for f in faces_of(t):
                face_tets.setdefault(f, set()).add(t)

        def remove(t):
            tets.discard(t)
            for f in faces_of(t):
                face_tets[f].discard(t)
                if not face_tets[f]:
                    del face_tets[f]

        for path in ((1, 3), (1, 5), (2, 3), (2, 6), (4, 5), (4, 6)):
            add((0, path[0], path[1], 7))
        for v in verts:
            if v < 8:
                continue
            start = next(t for t in tets if self.conflicts(t, v))
            cavity, stack = {start}, [start]
            while stack:
                t = stack.pop()
                for f in faces_of(t):
                    for s in face_tets[f]:
                        if s not in cavity and self.conflicts(s, v):
                            cavity.add(s)
                            stack.append(s)
            boundary = [f for t in cavity for f in faces_of(t) if not any(s in cavity for s in face_tets[f] if s != t)]
            for t in cavity:
                remove(t)
            for f in boundary:
                add(f + (v,))
        return tets

    def nearest2(self, u: int) -> int:
        return min(dist2(self.pts[u], q) for i, q in enumerate(self.pts) if i != u)

    def star(self, rest: Set[Tet], crit: Dict[Tet, Fraction], u: int, w) -> Tuple[Set[Tet], List[Tet]]:
        """The cavity {t in rest : crit[t] < w} and the cone from u over its boundary."""
        cavity = {t for t in rest if crit[t] < w}
        count: Dict[Face, int] = {}
        for t in cavity:
            for f in faces_of(t):
                count[f] = count.get(f, 0) + 1
        cone = []
        for f, m in count.items():
            if m == 1:
                t = f + (u,)
                o = orient3d(*[self.pts[x] for x in t])
                if o == 0:
                    raise AssertionError("flat tetrahedron in the star")
                cone.append(t if o > 0 else (t[1], t[0], t[2], t[3]))
        return cavity, cone

    def pump(self, u: int) -> int:
        P = self.pts
        rest = self.triangulate([v for v in range(len(P)) if v != u])  # @line L3
        crit = {t: critical_weight(*[P[x] for x in t], P[u], *[self.w[x] for x in t]) for t in rest}  # @line L4
        wmax = math.floor(self.omega**2 * self.nearest2(u))  # @line L5
        cuts = sorted({c for c in crit.values() if 0 < c < wmax})
        # the current weight 0, and one integer strictly inside each interval
        cands = [0]  # @line L6
        for lo, hi in zip([Fraction(0)] + cuts, cuts + [Fraction(wmax + 1)]):
            m = math.floor((lo + hi) / 2)
            for x in (m, m + 1, math.floor(lo) + 1):
                if lo < x < hi and x <= wmax:
                    cands.append(x)
                    break
        best = None
        for w in cands:
            if w != 0 and w in crit.values():
                continue
            cavity, cone = self.star(rest, crit, u, w)  # @line L7
            zeta = min_dihedral(P, cone)
            if best is None or zeta > best[0]:  # @line L8
                best = (zeta, w, cavity, cone)
        zeta0 = min_dihedral(P, self.star(rest, crit, u, 0)[1])
        _, w, cavity, cone = best
        self.w[u] = w  # @line L9
        self.tets = (rest - cavity) | set(cone)
        self.log.append((u, w, wmax, len(cands), zeta0, best[0]))
        return w

    def run(self) -> None:
        for u in range(8, len(self.pts)):  # @line L2
            self.pump(u)


def sliver_exudation(side: int, inner: Sequence[Sequence[int]], omega: Fraction = OMEGA) -> Exuder:
    """Pump every inner point once; return the Exuder with fields pts, w (weights) and tets."""
    e = Exuder(side, inner, omega)
    e.run()
    return e  # @line L10
test_sliver_exudation.py 311 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/sliver-exudation/. The authors are listed in prov/4WRSY6.jsonl.

import math
import random
from fractions import Fraction as F
from functools import lru_cache

import pytest

from mg2geom import circumcenter3, dihedral_angles_deg, dist2, insphere, orient3d, sub
from sliver_exudation import OMEGA, Exuder, critical_weight, faces_of, min_dihedral, power_test, sliver_exudation

S = 1000


def jittered_grid(seed, g, jit):
    """g^3 points near the grid points (i, j, k) * S, each coordinate moved by at most jit."""
    r = random.Random(seed)
    return [
        (i * S + r.randint(-jit, jit), j * S + r.randint(-jit, jit), k * S + r.randint(-jit, jit))
        for i in range(1, g + 1)
        for j in range(1, g + 1)
        for k in range(1, g + 1)
    ]


EXAMPLE = (2, 3, 100)  # seed, g, jitter: 27 inner points in a box of side 4000
OTHER = (1, 3, 150)


@lru_cache(maxsize=None)
def pumped(case):
    """Run the pumps one at a time and record the global minimum dihedral angle after each."""
    seed, g, jit = case
    e = Exuder((g + 1) * S, jittered_grid(seed, g, jit))
    before = (frozenset(e.tets), min_dihedral(e.pts, e.tets))
    mins = [before[1]]
    for u in range(8, len(e.pts)):
        e.pump(u)
        mins.append(min_dihedral(e.pts, e.tets))
    return e, before, mins


# brute-force orthosphere: center z and squared radius Z2 with |p - z|^2 - Z2 = w_p for the four points
def orthosphere(pts, ws):
    a, wa = pts[0], ws[0]
    rows, rhs = [], []
    for p, w in zip(pts[1:], ws[1:]):
        rows.append([F(2 * (p[k] - a[k])) for k in range(3)])
        rhs.append(F(sum(p[k] ** 2 - a[k] ** 2 for k in range(3)) - w + wa))
    # Gaussian elimination in exact arithmetic
    m = [rows[i] + [rhs[i]] for i in range(3)]
    for c in range(3):
        piv = next(i for i in range(c, 3) if m[i][c] != 0)
        m[c], m[piv] = m[piv], m[c]
        for i in range(3):
            if i != c and m[i][c] != 0:
                f = m[i][c] / m[c][c]
                m[i] = [x - f * y for x, y in zip(m[i], m[c])]
    z = tuple(m[i][3] / m[i][i] for i in range(3))
    return z, dist2(a, z) - wa


def random_weighted(r, n):
    pts = [tuple(r.randint(-20, 20) for _ in range(3)) for _ in range(n)]
    ws = [r.randint(0, 60) for _ in range(n)]
    return pts, ws


def test_power_test_matches_brute_force_orthosphere():
    r = random.Random(7)
    checked = signs = 0
    while checked < 300:
        pts, ws = random_weighted(r, 5)
        if orient3d(*pts[:4]) == 0:
            continue
        z, Z2 = orthosphere(pts[:4], ws[:4])
        pi = dist2(pts[4], z) - Z2 - ws[4]
        val = power_test(*pts, *ws)
        assert (val > 0) == (pi < 0) and (val == 0) == (pi == 0)
        assert val == -pi * abs(orient3d(*pts[:4]))
        assert critical_weight(*pts, *ws[:4]) == dist2(pts[4], z) - Z2
        # the order of the four points does not matter
        perm = [1, 0, 2, 3]
        assert power_test(*[pts[i] for i in perm], pts[4], *[ws[i] for i in perm], ws[4]) == val
        checked += 1
        signs += val > 0
    assert 0 < signs < 300


def test_power_test_with_zero_weights_is_insphere():
    r = random.Random(8)
    n = 0
    while n < 200:
        pts = [tuple(r.randint(-9, 9) for _ in range(3)) for _ in range(5)]
        if orient3d(*pts[:4]) == 0:
            continue
        assert power_test(*pts) == insphere(*pts)
        n += 1


def test_power_test_on_a_cube():
    c = [(x, y, z) for x in (0, 2) for y in (0, 2) for z in (0, 2)]
    t = (c[0], c[1], c[2], c[4])
    assert power_test(*t, (1, 1, 1)) > 0  # the center of the circumsphere
    assert power_test(*t, c[7]) == 0  # cospherical
    assert power_test(*t, (1, 1, 1), we=0) > 0
    # a center weight equal to its power distance makes it orthogonal: zero; more is a conflict, less is not
    pi = critical_weight(*t, (1, 1, 1))
    assert pi == dist2((1, 1, 1), (1, 1, 1)) - 3 == -3
    assert power_test(*t, (1, 1, 1), we=-3) == 0
    assert power_test(*t, (1, 1, 1), we=-4) < 0
    # (1, 1, 3) lies outside the circumsphere, power 4 - 3 = 1: a weight above 1 makes it conflict
    assert critical_weight(*t, (1, 1, 3)) == 1
    assert power_test(*t, (1, 1, 3)) < 0
    assert power_test(*t, (1, 1, 3), we=1) == 0
    assert power_test(*t, (1, 1, 3), we=2) > 0
    # a weight on the corner (0, 0, 2) pulls the orthosphere away from it, so (1, 1, 3) needs a larger weight
    assert critical_weight(*t, (1, 1, 3), 0, 4, 0, 0) > 1
    assert power_test(*t, (1, 1, 3), 0, 4, 0, 0, we=2) < 0


def test_flat_tetrahedron_raises():
    with pytest.raises(ValueError):
        power_test((0, 0, 0), (1, 0, 0), (0, 1, 0), (1, 1, 0), (0, 0, 1))


def check_regular(e):
    """Every tetrahedron has positive volume and no weighted point conflicts with it."""
    P, W = e.pts, e.w
    vol = 0
    for t in e.tets:
        o = orient3d(*[P[x] for x in t])
        assert o > 0
        vol += o
        for v in range(len(P)):
            if v not in t:
                assert power_test(*[P[x] for x in t], P[v], *[W[x] for x in t], W[v]) <= 0
    assert vol == 6 * e.side**3
    # every point is a vertex, and every face is shared by two tetrahedra or lies on the box
    assert {v for t in e.tets for v in t} == set(range(len(P)))
    count = {}
    for t in e.tets:
        for f in faces_of(t):
            count[f] = count.get(f, 0) + 1
    for f, m in count.items():
        if m == 1:
            assert any(all(P[v][k] in (0, e.side) and P[v][k] == P[f[0]][k] for v in f) for k in range(3))
        else:
            assert m == 2


@pytest.mark.parametrize("case", [EXAMPLE, OTHER])
def test_initial_triangulation_is_delaunay(case):
    seed, g, jit = case
    e = Exuder((g + 1) * S, jittered_grid(seed, g, jit))
    assert all(w == 0 for w in e.w)
    check_regular(e)


@pytest.mark.parametrize("case", [EXAMPLE, OTHER])
def test_final_triangulation_is_regular_and_unique(case):
    e, _, _ = pumped(case)
    check_regular(e)
    fresh = e.triangulate(range(len(e.pts)))
    assert {tuple(sorted(t)) for t in fresh} == {tuple(sorted(t)) for t in e.tets}


@pytest.mark.parametrize("case", [EXAMPLE, OTHER])
def test_weight_property(case):
    e, _, _ = pumped(case)
    P = e.pts
    for u in range(len(P)):
        assert e.w[u] >= 0
        for v in range(len(P)):
            if v != u:
                # U <= OMEGA |uv|, so the spheres of radius sqrt(w) are disjoint
                assert e.w[u] <= OMEGA**2 * dist2(P[u], P[v])
                assert math.sqrt(e.w[u]) + math.sqrt(e.w[v]) < math.sqrt(dist2(P[u], P[v]))
    assert all(e.w[u] == 0 for u in range(8))


@pytest.mark.parametrize("case", [EXAMPLE, OTHER])
def test_minimum_dihedral_never_decreases(case):
    e, before, mins = pumped(case)
    assert len(e.log) == len(e.pts) - 8
    for u, w, wmax, ncand, zeta0, best in e.log:
        assert 0 <= w <= wmax and ncand >= 1
        assert best >= zeta0
    for a, b in zip(mins, mins[1:]):
        assert b >= a
    assert mins[-1] > mins[0]


def test_star_matches_fresh_triangulation():
    """The star computed from critical weights equals Bowyer-Watson from scratch with that weight."""
    r = random.Random(3)
    e = Exuder(3 * S, jittered_grid(5, 2, 150))
    P = e.pts
    for u in range(8, len(P)):
        rest = e.triangulate([v for v in range(len(P)) if v != u])
        crit = {t: critical_weight(*[P[x] for x in t], P[u], *[e.w[x] for x in t]) for t in rest}
        wmax = math.floor(OMEGA**2 * e.nearest2(u))
        for w in [0, wmax] + [r.randint(0, wmax) for _ in range(4)]:
            if w in crit.values():
                continue
            cavity, cone = e.star(rest, crit, u, w)
            e.w[u] = w
            fresh = e.triangulate(range(len(P)))
            e.w[u] = 0
            assert {tuple(sorted(t)) for t in (rest - cavity) | set(cone)} == {tuple(sorted(t)) for t in fresh}
        e.pump(u)


@pytest.mark.parametrize("u", [9, 18, 21, 26, 30])
def test_pump_finds_the_best_star(u):
    """Brute force: try the midpoint of every interval between critical weights, and many integers."""
    e = Exuder(4 * S, jittered_grid(*EXAMPLE))
    P = e.pts
    rest = e.triangulate([v for v in range(len(P)) if v != u])
    crit = {t: critical_weight(*[P[x] for x in t], P[u]) for t in rest}
    wmax = math.floor(OMEGA**2 * e.nearest2(u))
    cuts = sorted({c for c in crit.values() if 0 < c < wmax})
    trial = [F(0)] + [(lo + hi) / 2 for lo, hi in zip([F(0)] + cuts, cuts + [F(wmax)])]
    trial += [F(w) for w in range(1, wmax + 1, 499)]
    best = max(min_dihedral(P, e.star(rest, crit, u, w)[1]) for w in trial if w not in crit.values())
    e.pump(u)
    # the current weight 0, and at most one integer in each of the len(cuts) + 1 intervals
    assert e.log[-1][3] <= len(cuts) + 2
    assert e.log[-1][5] == pytest.approx(best, abs=1e-9)


def test_example_numbers():
    e, before, mins = pumped(EXAMPLE)
    P = e.pts
    tets0, min0 = before
    lo0 = [min(dihedral_angles_deg(*[P[v] for v in t])) for t in tets0]
    lo1 = [min(dihedral_angles_deg(*[P[v] for v in t])) for t in e.tets]
    assert (len(tets0), len(e.tets)) == (151, 139)
    assert round(min0, 2) == 0.14 and round(mins[-1], 2) == 5.20
    assert (sum(a < 5 for a in lo0), sum(a < 5 for a in lo1)) == (9, 0)
    assert (sum(a < 10 for a in lo0), sum(a < 10 for a in lo1)) == (17, 6)
    assert sum(1 for w in e.w if w) == 11
    # the worst sliver: four vertices near the face x = 3000, angles 0.14 and 179.78 degrees
    worst = min(tets0, key=lambda t: min(dihedral_angles_deg(*[P[v] for v in t])))
    assert sorted(worst) == [26, 27, 29, 30]
    ang = dihedral_angles_deg(*[P[v] for v in worst])
    assert round(max(ang), 2) == 179.78
    # its radius-edge ratio is small: the ratio does not see it
    cc = circumcenter3(*[P[v] for v in worst])
    lmin = min(dist2(P[a], P[b]) for a in worst for b in worst if a < b)
    assert dist2(cc, P[worst[0]]) / lmin < 9
    # the pump of vertex 26 removes it
    row = next(x for x in e.log if x[0] == 26)
    assert row[1] == 44845 and round(row[4], 2) == 0.14 and round(row[5], 2) == 5.47
    # the global minimum rises at the pumps of 26 and 30 only
    assert [i + 8 for i in range(len(mins) - 1) if mins[i + 1] > mins[i]] == [26, 30]


def test_second_example_worst_touches_a_corner():
    e, _, mins = pumped(OTHER)
    assert round(mins[0], 2) == 1.54 and round(mins[-1], 2) == 3.03
    worst = min(e.tets, key=lambda t: min(dihedral_angles_deg(*[e.pts[v] for v in t])))
    assert min(worst) < 8


def test_dihedral_lower_bound_from_volume_and_edge_ratio():
    """sin(theta) >= 8 Sigma / lambda^4 with Sigma = V / L^3 and lambda = D / L, on every tetrahedron."""
    for case in (EXAMPLE, OTHER):
        e, before, _ = pumped(case)
        P = e.pts
        for t in set(before[0]) | e.tets:
            q = [P[v] for v in t]
            V = F(abs(orient3d(*q)), 6)
            e2 = [dist2(q[a], q[b]) for a in range(4) for b in range(a + 1, 4)]
            L, D = math.sqrt(min(e2)), math.sqrt(max(e2))
            bound = 8 * float(V) * L / D**4  # 8 (V / L^3) / (D / L)^4
            theta = min(dihedral_angles_deg(*q))
            assert math.sin(math.radians(theta)) >= bound * (1 - 1e-9)


@pytest.mark.parametrize("case", [EXAMPLE, OTHER])
def test_longest_edge_bounded_by_orthoradius(case):
    """With the Weight Property, D^2 (1 - 4 OMEGA^2) <= 4 Z^2 for every tetrahedron of the output."""
    e, _, _ = pumped(case)
    P, W = e.pts, e.w
    for t in e.tets:
        q, ws = [P[v] for v in t], [W[v] for v in t]
        z, Z2 = orthosphere(q, ws)
        assert Z2 > 0
        for p, w in zip(q, ws):
            assert dist2(p, z) - Z2 == w
        D2 = max(dist2(q[a], q[b]) for a in range(4) for b in range(a + 1, 4))
        assert D2 * (1 - 4 * OMEGA**2) <= 4 * Z2


def test_entry_point_and_bad_input():
    e = sliver_exudation(2 * S, [(1000, 1000, 1000)])
    assert len(e.tets) == 12 and e.w[8] <= OMEGA**2 * 3 * 10**6
    check_regular(e)
    with pytest.raises(ValueError):
        Exuder(0, [])
    with pytest.raises(ValueError):
        Exuder(10, [(5, 5, 5)], omega=F(1, 2))
    with pytest.raises(ValueError):
        Exuder(10, [(5, 5, 5), (5, 5, 5)])
    with pytest.raises(ValueError):
        Exuder(10, [(0, 5, 5)])
    with pytest.raises(ValueError):
        Exuder(10, [(5, 5, 11)])

History

Slivers were known as the weak point of three-dimensional Delaunay refinement through the 1990s: Shewchuk's 1998 analysis bounds only the radius-edge ratio, and Chew's 1997 method removes slivers by random choice with a weak guarantee. Cheng, Dey, Edelsbrunner, Facello and Teng presented sliver exudation at SoCG 1999 and in the Journal of the ACM in 2000, with the first proof that weights alone can remove slivers. Edelsbrunner and Guoy tested it in 2002 and found the minimum angle reaches about 5°5° in practice. Cheng and Dey combined it with refinement for domains with boundaries, and the material forms Chapters 10 and 11 of Cheng, Dey and Shewchuk's Delaunay Mesh Generation (2013).

References

  1. Siu-Wing Cheng, Tamal K. Dey, Herbert Edelsbrunner, Michael A. Facello and Shang-Hua Teng, Sliver exudation, Journal of the ACM 47(5), 2000, 883 to 904, Section 2.4 (Ratio Property), Section 4.2 (Weight Property), Section 4.5 (the measure Sigma), Section 5.1 (periodic point sets and Claim 7, the Weighted Ratio Property), Section 6.5 (the Sliver Theorem), Section 7.1 (pumping and the skyline), Section 8.1 (the constant is "miserably tiny")
  2. Siu-Wing Cheng, Tamal K. Dey, Herbert Edelsbrunner, Michael A. Facello and Shang-Hua Teng, Sliver exudation, Proceedings of the 15th Annual Symposium on Computational Geometry, 1999, 1 to 13, the conference version (general locator)
  3. Herbert Edelsbrunner and Damrong Guoy, An experimental study of sliver exudation, Engineering with Computers 18(3), 2002, 229 to 240, Section 3 (function Pump with the bound 0.45 d_u, the O(n) running time, the remark that the proved constant is "positive but miserably small" and around 5 degrees in practice), Section 4 (experiments), Section 5 (the boundary as the main limitation)
  4. Siu-Wing Cheng, Tamal K. Dey and Jonathan Richard Shewchuk, Delaunay Mesh Generation, CRC Press, 2013, Chapter 7 (weighted Delaunay triangulations, pages 169 to 184), Chapter 10 (sliver exudation, pages 223 to 246), Chapter 11 (refinement for sliver exudation, pages 247 to 260)
  5. Siu-Wing Cheng and Tamal K. Dey, Quality meshing with weighted Delaunay refinement, SIAM Journal on Computing 33(1), 2003, 69 to 93, Section 5 (pumping mixed with refinement for polyhedral domains, Lemma 5.1 on the orthoradius-edge ratio)
  6. François Labelle and Jonathan Richard Shewchuk, Isosurface stuffing, fast tetrahedral meshes with good dihedral angles, ACM Transactions on Graphics 26(3), 2007, article 57, Section 2, the remark that the provable angle bounds of Delaunay methods with sliver removal are below 0.1 degree and probably below a millionth of a degree

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of time.worst
  • a full proof of space.extra
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a scene preset for the example