Algorithm Search⌘K

Algorithmadvanced

Owen's triconnected decomposition

Also called top-down constraint decomposition.

Owen's solver that splits the constraint graph at separation pairs into triconnected parts, solves each and reassembles them, for systems solvable by quadratics.

Time
O(n^2) worst
Space
O(n^2) extra
Where
m = the number of distance constraints, 2n - 3; n = the number of points
Properties
deterministicexactrecursive
Origin
John C. Owen, 1991

Owen's decomposition is the top-down form of graph-constructive solving for planar sketches. It looks for a separation pair {a,b}\{a, b\}, two points whose removal cuts the constraint graph in two. One side is rigid by itself; the other side is rigid once the distance ∣ab∣\lvert ab \rvert is known, so the method gives it a virtual edge abab. Both sides are split again in the same way until every part is a triangle. The solver then works from the leaves: it solves the rigid side, measures ∣ab∣\lvert ab \rvert there, solves the other side with that length, and glues the two sides at aa and bb by a rigid motion. Each triangle is one circle-circle intersection, so the solution needs only square roots. The method stops at a part with four or more points and no separation pair, that is, a 3-connected part such as the triangular prism, and these parts are exactly where square roots do not suffice. With a linear-time search for separation pairs the analysis takes O(n2)O(n^2) time.

In plain words

Look at the sketch as a network of rods. Sometimes two joints hold the whole network together: if you pull them out, it falls into two pieces. Each piece is easier to solve than the whole.

One piece is fixed in shape by its own rods. The other piece is not, since it misses one rod: the one that the first piece holds in place between the two joints. So you solve the first piece, measure the distance between the two joints, and add that distance to the second piece as an extra rod. Now the second piece is fixed too. You solve it and lay it onto the first piece at the two joints.

Each piece is cut again until only triangles are left. A triangle with known sides is easy to draw with ruler and compass. If a piece cannot be cut, the method stops.

The problem

Input. A Laman graph G=(V,E)G = (V, E): n≥3n \ge 3 points and m=2n−3m = 2n - 3 distance constraints, with every k≥2k \ge 2 points spanning at most 2k−32k - 3 edges, as in Laman's theorem. Each edge has a length d(uv)>0d(uv) > 0. An optional integer draft x^\hat x shows the intended shape.

Output. A decomposition tree whose leaves are triangles, or a report that some part is 3-connected and has no separation pair. For a tree, the solver also returns a placement x:V→R2x : V \to \mathbb{R}^2 with ∣x(u)−x(v)∣=d(uv)\lvert x(u) - x(v) \rvert = d(uv) for every edge; each leaf triangle has the orientation of the draft.

Separation pairs. A pair {a,b}\{a, b\} is a separation pair of a part with vertex set PP if the graph on P∖{a,b}P \setminus \{a, b\} is not connected. A Laman graph with at least 3 points is 2-connected, so a separation pair is the smallest kind of vertex cut that it can have, and a part with no separation pair is 3-connected. Owen finds the pairs with the triconnected components algorithm of Hopcroft and Tarjan; this page splits at one pair at a time, which is simpler to state and to prove.

The algorithm

  1. OWEN-DECOMPOSE(P, F) ▷ a part: points P, edges F (real and virtual)
  2. 1if |F| ≠ 2|P| − 3 then fail "not a Laman graph"
  3. 2if |P| = 3 then return TRI(P)
  4. 3{a, b} ← a separation pair of (P, F)
  5. 4if there is none then return FAIL ▷ the part is 3-connected
  6. 5K ← one component of the graph on P − {a, b}; P1 ← K ∪ {a, b}; P2 ← P − K
  7. 6F1 ← the edges inside P1, with ab if ab ∈ F; F2 ← the rest; if |F1| < 2|P1| − 3 then swap the two sides
  8. 7F2 ← F2 ∪ {ab}, marked virtual if ab ∉ F; return SPLIT(a, b, OWEN-DECOMPOSE(P1, F1), OWEN-DECOMPOSE(P2, F2))
  9. OWEN-SOLVE(T, d, x̂)
  10. 8if T = TRI(u, v, w) then place u at (0, 0), v at (d(uv), 0), and w at distances d(uw), d(vw) on the side of the sign of ORIENT(x̂(u), x̂(v), x̂(w)), computed exactly, 0 counting as +1; return
  11. 9T = SPLIT(a, b, T1, T2); X1 ← OWEN-SOLVE(T1, d, x̂) ▷ the rigid side first
  12. 10if ab is virtual then d(ab) ← |X1(a) − X1(b)|; X2 ← OWEN-SOLVE(T2, d, x̂)
  13. 11return X1 together with X2 moved by the proper rigid motion that takes X2(a), X2(b) to X1(a), X1(b)

The split. Line L1 checks the count on each part, which also catches a wrong input. Line L3 finds a separation pair; with the Hopcroft-Tarjan low-point search for articulation points, run once with each point aa removed, it costs O(k(k+mk))O(k(k + m_k)) for a part with kk points and mkm_k edges, and Hopcroft and Tarjan's triconnectivity algorithm does it in O(k+mk)O(k + m_k). Line L5 takes one component KK and gives the pair to both sides. Line L6 puts each edge on its side: an edge cannot join KK to the rest, because {a,b}\{a, b\} separates them. The two sides together have one edge too few to be two Laman graphs, so exactly one side has the full count 2∣Pi∣−32|P_i| - 3 and the other has one edge less; line L6 makes the full side the first side. Line L7 gives the other side the edge abab, which makes it a Laman graph too.

The solve. Line L8 draws a triangle. Lines L9 and L10 solve the rigid side first, because the length of a virtual edge is not a given value: it is measured on the solved rigid side. A real edge abab keeps its given length on both sides. Line L11 glues the two sides. The two placements agree on ∣ab∣\lvert ab \rvert, so one rotation and one translation take aa and bb of the second side onto aa and bb of the first; the motion is proper, so it keeps the orientations that the triangles chose.

The sign. The draft enters only in line L8, through the orientation test of the three draft points. In floating point a nearly flat draft triangle can get the wrong sign by catastrophic cancellation, and the leaf is then mirrored. The draft here has integer coordinates and the sign is exact; for a floating-point draft use exact arithmetic or a filtered predicate such as Shewchuk's, as in exact geometric computation. A flat draft triangle gives 0, and the rule "0 counts as +1" is a crude form of simulation of simplicity. A Laman graph that decomposes has n−2n - 2 leaves, so a vector of n−2n - 2 signs selects one of up to 2n−22^{n-2} branches.

Example

Take the six points with the constraints 01,02,12,34,35,45,03,04,1501, 02, 12, 34, 35, 45, 03, 04, 15: two triangles {0,1,2}\{0, 1, 2\} and {3,4,5}\{3, 4, 5\}, joined by bars 0303 and 0404 at point 0 and by the bar 1515. The draft is (0,0)(0, 0), (6,0)(6, 0), (3,−4)(3, -4), (−1,5)(-1, 5), (3,6)(3, 6), (7,4)(7, 4) for the points 0 to 5, and the lengths are measured on it, with ∣01∣2=36\lvert 01 \rvert^2 = 36, ∣02∣2=∣12∣2=25\lvert 02 \rvert^2 = \lvert 12 \rvert^2 = 25, ∣34∣2=17\lvert 34 \rvert^2 = 17, ∣35∣2=65\lvert 35 \rvert^2 = 65, ∣45∣2=20\lvert 45 \rvert^2 = 20, ∣03∣2=26\lvert 03 \rvert^2 = 26, ∣04∣2=45\lvert 04 \rvert^2 = 45 and ∣15∣2=17\lvert 15 \rvert^2 = 17. Its separation pairs are {0,1}\{0, 1\} and {0,5}\{0, 5\}. The decomposition makes three splits.

part pair rigid side (first) other side, with abab
{0,1,2,3,4,5}\{0, 1, 2, 3, 4, 5\} {0,1}\{0, 1\}, a real edge {0,1,2}\{0, 1, 2\} {0,1,3,4,5}\{0, 1, 3, 4, 5\}, edges 34,35,45,03,04,1534, 35, 45, 03, 04, 15 and 0101
{0,1,3,4,5}\{0, 1, 3, 4, 5\} {0,5}\{0, 5\}, not an edge {0,3,4,5}\{0, 3, 4, 5\}, after the swap {0,1,5}\{0, 1, 5\}, edges 01,1501, 15 and virtual 0505
{0,3,4,5}\{0, 3, 4, 5\} {3,4}\{3, 4\}, a real edge {0,3,4}\{0, 3, 4\} {3,4,5}\{3, 4, 5\}

At the second split the component found first is K={1}K = \{1\}, so line L6 first gets the side {0,1,5}\{0, 1, 5\} with only the two edges 0101 and 1515, and it swaps the sides. The four leaves are solved in this order; the last column is the exact orientation of the draft points.

leaf squared sides uvuv, uwuw, vwvw ORIENT where the lengths come from
(0,1,2)(0, 1, 2) 36, 25, 25 −24-24 given
(0,3,4)(0, 3, 4) 26, 45, 17 −21-21 given
(3,4,5)(3, 4, 5) 17, 65, 20 −12-12 given; then glued at {3,4}\{3, 4\} into {0,3,4,5}\{0, 3, 4, 5\}
(0,1,5)(0, 1, 5) 36, 65, 17 +24+24 ∣05∣2=65\lvert 05 \rvert^2 = 65 is measured on {0,3,4,5}\{0, 3, 4, 5\} by line L10

Gluing at {0,5}\{0, 5\} and then at {0,1}\{0, 1\} gives the whole placement. The first leaf puts 0 at the origin and 1 at (6,0)(6, 0), as in the draft, so OWEN-SOLVE returns the draft itself. With other sign vectors, the measured length changes: if the leaves (0,3,4)(0, 3, 4) and (3,4,5)(3, 4, 5) put 0 and 5 on opposite sides of the line 34, then ∣05∣2=2113/17≈124.3\lvert 05 \rvert^2 = 2113/17 \approx 124.3, the leaf (0,1,5)(0, 1, 5) violates the triangle inequality, and the branch has no real solution. So 8 of the 16 sign vectors give real placements.

The triangular prism, with the bars 03,14,2503, 14, 25 instead, is 3-connected: removing any two points leaves a connected graph. Line L4 fails at the root, although the prism is well-constrained for generic lengths. A triangle-decomposable graph is well-constrained, but a well-constrained graph need not be triangle-decomposable.

Correctness

The proof shows the following for a Laman graph GG.

  • The split keeps Laman graphs. Each side has fewer points than the part. The side chosen first in line L6 is a Laman graph, and the other side becomes one when line L7 adds abab; no set of its points that holds aa and bb can have the full count without abab, because together with the rigid side it would break the count of GG.
  • The split lemma. GG is triangle-decomposable, in the sense of the Fudos-Hoffmann reduction, exactly when both sides are. For one direction, the merges of the second side, with the edge abab replaced by the rigid cluster of the first side, are merges of GG. For the other direction, intersect each cluster of GG with each side; the counts force the intersections to be clusters of the sides.
  • Every decomposable part with 4 or more points has a separation pair. In the last merge of three clusters, one cluster has 3 or more points, and its two shared points cut it from the other two clusters.
  • So the choice of pairs does not matter. By induction, OWEN-DECOMPOSE returns a tree, whatever separation pairs and components it picks, exactly when GG is triangle-decomposable. This is the theorem of Joan-Arinyo and his coauthors in the form for points and distances.
  • The solution. Each part is placed so that its constraints hold, and the glue is exact. If the lengths come from the draft and no leaf triangle is flat in the draft, the result is the draft moved by a proper rigid motion. Every real solution that keeps the two points of each virtual edge apart comes from one sign vector.
Proof: Owen's decomposition splits a Laman graph down to triangles, for any choice of separation pairs, exactly when the graph is triangle-decomposable, and the solve gives every nondegenerate solutionfull

A part is a graph H=(P,F)H = (P, F) whose edges may include virtual edges; a virtual edge is an ordinary edge for all counts. For X⊆PX \subseteq P let F(X)F(X) be the set of edges with both ends in XX and i(X)=∣F(X)∣i(X) = |F(X)|. HH is sparse if i(X)≤2∣X∣−3i(X) \le 2|X| - 3 for all XX with ∣X∣≥2|X| \ge 2, and Laman if it is sparse and ∣F∣=2∣P∣−3|F| = 2|P| - 3. A set XX with ∣X∣≥2|X| \ge 2 is rigid in HH if i(X)=2∣X∣−3i(X) = 2|X| - 3. HH is triangle-decomposable (TD) if the Fudos-Hoffmann reduction on HH ends with the single cluster PP; by the confluence theorem of that reduction, this does not depend on the order of the merges. Line numbers refer to the pseudocode on the main page. Three facts are used often.

  • (F1) A Laman graph with at least 3 points is 2-connected. If vv were a cut vertex, with P=P′∪P′′P = P' \cup P'', P′∩P′′={v}P' \cap P'' = \{v\} and no edge between P′−vP' - v and P′′−vP'' - v, then ∣F∣≤(2∣P′∣−3)+(2∣P′′∣−3)=2∣P∣−4|F| \le (2|P'| - 3) + (2|P''| - 3) = 2|P| - 4.
  • (F2) In a sparse graph, if XX and YY are rigid and ∣X∩Y∣≥2|X \cap Y| \ge 2, then X∩YX \cap Y is rigid. Each edge inside XX or inside YY lies inside X∪YX \cup Y, and each edge inside both lies inside X∩YX \cap Y, so i(X∪Y)+i(X∩Y)≥i(X)+i(Y)=2∣X∪Y∣−3+2∣X∩Y∣−3i(X \cup Y) + i(X \cap Y) \ge i(X) + i(Y) = 2|X \cup Y| - 3 + 2|X \cap Y| - 3. Both terms on the left are at most their bounds, so both are equal to them.
  • (F3) In a run of the reduction on a sparse graph, every cluster CC is rigid, its edge set is F(C)F(C), and two clusters share at most one point (Lemma 1 of the reduction's proof).

Lemma 1 (one merge at the top). Let H=(P,F)H = (P, F) be Laman with ∣P∣≥3|P| \ge 3. Then HH is TD if and only if P=A∪B∪CP = A \cup B \cup C, where A∩B={p}A \cap B = \{p\}, A∩C={q}A \cap C = \{q\}, B∩C={r}B \cap C = \{r\} with p,q,rp, q, r distinct, the sets F(A)F(A), F(B)F(B), F(C)F(C) partition FF, and each of (A,F(A))(A, F(A)), (B,F(B))(B, F(B)), (C,F(C))(C, F(C)) is a single edge or TD.

Proof. If HH is TD, take the last merge of a run; by (F3) its three clusters have these properties. Conversely, the merges that reduce (A,F(A))(A, F(A)) to one cluster are merges of HH, since validity depends only on the three clusters involved. Do them, then those of BB and CC. The edge sets partition FF, so the clusters AA, BB, CC are the whole state, and they form a valid triple. Merging them gives PP, and by confluence every run ends there. □\square

Now fix a Laman part H=(P,F)H = (P, F) with ∣P∣≥4|P| \ge 4 and a separation pair {a,b}\{a, b\}, and let P1P_1, P2P_2, F1F_1, F2F_2 be the sets of lines L5 to L7, after the swap of line L6. Write H1=(P1,F1)H_1 = (P_1, F_1) and H2=(P2,F2∪{ab})H_2 = (P_2, F_2 \cup \{ab\}), and let Qi=Pi∖{a,b}Q_i = P_i \setminus \{a, b\}. The graph on P∖{a,b}P \setminus \{a, b\} has no edge between Q1Q_1 and Q2Q_2, and both are nonempty.

Lemma 2 (the split keeps Laman graphs). H1H_1 and H2H_2 are Laman, 3≤∣Pi∣<∣P∣3 \le |P_i| < |P|, and F1=F(P1)F_1 = F(P_1), the set of all edges of HH inside P1P_1. In particular, line L1 never fails on a part of a Laman graph.

Proof. ∣Pi∣=∣Qi∣+2|P_i| = |Q_i| + 2 with 1≤∣Qi∣≤∣P∣−31 \le |Q_i| \le |P| - 3. Before the swap, line L6 puts in the first side all edges inside P1P_1, the edge abab included if ab∈Fab \in F, and in the second side all other edges, which lie inside P2P_2. Let δi=2∣Pi∣−3−∣Fi∣\delta_i = 2|P_i| - 3 - |F_i|. Sparsity of HH gives δ1≥0\delta_1 \ge 0 and δ2≥0\delta_2 \ge 0, and if ab∈Fab \in F, then ∣F2∣+1=i(P2)≤2∣P2∣−3|F_2| + 1 = i(P_2) \le 2|P_2| - 3, so δ2≥1\delta_2 \ge 1. Since ∣P1∣+∣P2∣=∣P∣+2|P_1| + |P_2| = |P| + 2,

δ1+δ2=2∣P1∣+2∣P2∣−6−(2∣P∣−3)=1.\delta_1 + \delta_2 = 2|P_1| + 2|P_2| - 6 - (2|P| - 3) = 1.

So exactly one side has δ=0\delta = 0. If ab∈Fab \in F, it is the first side, and there is no swap. If ab∉Fab \notin F, line L6 swaps the sides when δ1=1\delta_1 = 1; in both cases F1=F(P1)F_1 = F(P_1). So after line L6, ∣F1∣=2∣P1∣−3|F_1| = 2|P_1| - 3, and H1H_1 is sparse as a subgraph of HH, so it is Laman. Line L7 gives H2H_2 the count 2∣P2∣−32|P_2| - 3. For sparsity, let X⊆P2X \subseteq P_2 with ∣X∣≥2|X| \ge 2. If XX does not hold both aa and bb, its edges in H2H_2 are edges of HH, and i(X)≤2∣X∣−3i(X) \le 2|X| - 3. If it does, suppose ∣F2(X)∣≥2∣X∣−3|F_2(X)| \ge 2|X| - 3. The edges of F1F_1 and of F2(X)F_2(X) are distinct edges of HH inside X∪P1X \cup P_1, and ∣X∩P1∣=2|X \cap P_1| = 2, so

i(X∪P1)≥2∣P1∣−3+2∣X∣−3=2∣X∪P1∣−2,i(X \cup P_1) \ge 2|P_1| - 3 + 2|X| - 3 = 2|X \cup P_1| - 2,

which contradicts sparsity of HH. So ∣F2(X)∣≤2∣X∣−4|F_2(X)| \le 2|X| - 4, and with abab the set XX has at most 2∣X∣−32|X| - 3 edges. □\square

For Y⊆PiY \subseteq P_i, let Fi′(Y)F'_i(Y) be the set of edges of HiH_i inside YY and ii′(Y)=∣Fi′(Y)∣i'_i(Y) = |F'_i(Y)|. Write Hi[Y]=(Y,Fi′(Y))H_i[Y] = (Y, F'_i(Y)).

Lemma 3 (clusters meet the sides in rigid sets). Let XX be a cluster of a run of the reduction on HH, and let Xi=X∩PiX_i = X \cap P_i with ∣Xi∣≥2|X_i| \ge 2. Then ii′(Xi)=2∣Xi∣−3i'_i(X_i) = 2|X_i| - 3. Also, if XX meets both Q1Q_1 and Q2Q_2, then a,b∈Xa, b \in X.

Proof. For the last claim: an edge cluster cannot meet both, since no edge joins Q1Q_1 to Q2Q_2. A larger cluster is rigid by (F3), so H[X]H[X] is Laman with at least 3 points and 2-connected by (F1). Every path from Q1Q_1 to Q2Q_2 in it passes through aa or bb. If XX missed one of them, the other would be a cut vertex of H[X]H[X], or H[X]H[X] would not be connected.

Side 1: P1P_1 and XX are rigid in HH by Lemma 2 and (F3), so X1X_1 is rigid by (F2), and its edges in HH are those of H1H_1 because F1=F(P1)F_1 = F(P_1).

Side 2, in three cases. If X∩Q1=∅X \cap Q_1 = \emptyset, then X=X2X = X_2. Its edges in H2H_2 are its edges in HH, except that the edge abab, if both its ends are in XX, is counted once in either graph. If a,b∈Xa, b \in X and ab∉Fab \notin F, then i2′(X)=2∣X∣−2i'_2(X) = 2|X| - 2, which contradicts Lemma 2. Otherwise i2′(X)=i(X)=2∣X∣−3i'_2(X) = i(X) = 2|X| - 3. If XX meets Q1Q_1 and Q2Q_2, then a,b∈Xa, b \in X, and X1⊇{a,b}X_1 \supseteq \{a, b\} is rigid with ∣X1∣≥3|X_1| \ge 3. Each edge inside XX lies inside X1X_1 or is an edge of F2F_2 inside X2X_2, so ∣F2(X2)∣=2∣X∣−3−(2∣X1∣−3)=2∣X2∣−4|F_2(X_2)| = 2|X| - 3 - (2|X_1| - 3) = 2|X_2| - 4, using ∣X∣=∣X1∣+∣X2∣−2|X| = |X_1| + |X_2| - 2. Adding abab gives 2∣X2∣−32|X_2| - 3. If XX meets Q1Q_1 but not Q2Q_2, then X2⊆{a,b}X_2 \subseteq \{a, b\}, so X2={a,b}X_2 = \{a, b\} with the one edge abab. □\square

Lemma 4 (split lemma). HH is TD if and only if H1H_1 and H2H_2 are TD.

Proof. (⇐\Leftarrow) Since F1=F(P1)F_1 = F(P_1), the merges that reduce H1H_1 to the cluster P1P_1 are merges of HH. Now replay a run of H2H_2 that ends in P2P_2, with one change: a cluster XX of H2H_2 whose edge set holds abab becomes X∪P1X \cup P_1, with the edges of F1F_1 in place of abab. At each step at most one cluster holds abab, and it contains aa and bb. Any other cluster Y⊆P2Y \subseteq P_2 meets P1P_1 only inside {a,b}⊆X\{a, b\} \subseteq X, so Y∩(X∪P1)=Y∩XY \cap (X \cup P_1) = Y \cap X. The pairwise intersections do not change, so every merge stays valid, and the run ends with P2∪P1=PP_2 \cup P_1 = P.

(⇒\Rightarrow) Take a run on HH that ends with PP. We show by induction over the order of formation: for each cluster XX and each side ii with ∣Xi∣≥2|X_i| \ge 2, Hi[Xi]H_i[X_i] is a single edge or TD. For X=PX = P this gives the claim.

An edge cluster {u,v}\{u, v\} with {u,v}⊆Pi\{u, v\} \subseteq P_i is an edge of HiH_i: either uv∈Fiuv \in F_i, or uv=abuv = ab, which is in H2H_2 by line L7 and in F1F_1 when it is real.

Let X=A∪B∪CX = A \cup B \cup C be a merge with A∩B={p}A \cap B = \{p\}, A∩C={q}A \cap C = \{q\}, B∩C={r}B \cap C = \{r\}, and fix a side ii with ∣Xi∣≥2|X_i| \ge 2. By induction, for Y∈{A,B,C}Y \in \{A, B, C\} with ∣Yi∣≥2|Y_i| \ge 2, Hi[Yi]H_i[Y_i] is TD or an edge, so ii′(Yi)=2∣Yi∣−3i'_i(Y_i) = 2|Y_i| - 3; if ∣Yi∣≤1|Y_i| \le 1, then ii′(Yi)=0i'_i(Y_i) = 0.

(a) The sets Fi′(Ai)F'_i(A_i), Fi′(Bi)F'_i(B_i), Fi′(Ci)F'_i(C_i) are disjoint subsets of Fi′(Xi)F'_i(X_i) that miss at most one edge of it. An edge of FiF_i inside XiX_i is an edge of HH inside XX, so by (F3) it is inside exactly one of AA, BB, CC, and so inside one of AiA_i, BiB_i, CiC_i. The only other edge is abab on side 2. Two of A2,B2,C2A_2, B_2, C_2 cannot both contain aa and bb, because the clusters share at most one point. Let ε=1\varepsilon = 1 if i=2i = 2, a,b∈X2a, b \in X_2 and none of A2,B2,C2A_2, B_2, C_2 contains both; otherwise ε=0\varepsilon = 0. Then

2∣Xi∣−3=ii′(Xi)=ii′(Ai)+ii′(Bi)+ii′(Ci)+ε,2|X_i| - 3 = i'_i(X_i) = i'_i(A_i) + i'_i(B_i) + i'_i(C_i) + \varepsilon,

where the first equality is Lemma 3.

(b) If ∣Ai∣≥2|A_i| \ge 2 and ∣Bi∣≥2|B_i| \ge 2, then p∈Pip \in P_i. Otherwise pp lies in QjQ_j for the other side jj. Then AA holds p∈Qjp \in Q_j and two points of PiP_i; either AA meets QiQ_i, and Lemma 3 gives a,b∈Aa, b \in A, or Ai⊆{a,b}A_i \subseteq \{a, b\} with ∣Ai∣≥2|A_i| \ge 2. Either way a,b∈Aa, b \in A, and in the same way a,b∈Ba, b \in B, so A∩B⊇{a,b,p}A \cap B \supseteq \{a, b, p\}, a contradiction. The same holds for the other two pairs.

Let tt be the number of Y∈{A,B,C}Y \in \{A, B, C\} with ∣Yi∣≥2|Y_i| \ge 2.

  • t=3t = 3. By (b), Ai∩Bi={p}A_i \cap B_i = \{p\}, Ai∩Ci={q}A_i \cap C_i = \{q\} and Bi∩Ci={r}B_i \cap C_i = \{r\}, so ∣Xi∣=∣Ai∣+∣Bi∣+∣Ci∣−3|X_i| = |A_i| + |B_i| + |C_i| - 3, and (a) reads 2∣Xi∣−3=2∣Xi∣−3+ε2|X_i| - 3 = 2|X_i| - 3 + \varepsilon. So ε=0\varepsilon = 0, the three edge sets partition Fi′(Xi)F'_i(X_i), and Lemma 1 shows that Hi[Xi]H_i[X_i] is TD. It is Laman: its count is that of Lemma 3, and it is a subgraph of the sparse graph HiH_i.
  • t=2t = 2, say ∣Ai∣,∣Bi∣≥2≥∣Ci∣+1|A_i|, |B_i| \ge 2 \ge |C_i| + 1. By (b), ∣Ai∪Bi∣=∣Ai∣+∣Bi∣−1|A_i \cup B_i| = |A_i| + |B_i| - 1, and (a) gives 2∣Xi∣−3=2∣Ai∪Bi∣−4+ε2|X_i| - 3 = 2|A_i \cup B_i| - 4 + \varepsilon. Since Xi⊇Ai∪BiX_i \supseteq A_i \cup B_i, this forces ε=1\varepsilon = 1 and Xi=Ai∪BiX_i = A_i \cup B_i. So i=2i = 2, and aa and bb lie in A2∪B2A_2 \cup B_2 with neither set holding both. Neither of them is pp, since pp lies in both sets; so, after renaming, a∈A2∖B2a \in A_2 \setminus B_2 and b∈B2∖A2b \in B_2 \setminus A_2. Then A2A_2, B2B_2 and the edge {a,b}\{a, b\} pairwise share pp, aa and bb, which are distinct, their edge sets partition F2′(X2)F'_2(X_2), and Lemma 1 shows that H2[X2]H_2[X_2] is TD. The cases with another pair of clusters are the same.
  • t=1t = 1, say ∣Ai∣≥2|A_i| \ge 2. (a) gives 2∣Xi∣−3=2∣Ai∣−3+ε2|X_i| - 3 = 2|A_i| - 3 + \varepsilon, so ε=0\varepsilon = 0 and Xi=AiX_i = A_i, which is TD or an edge by induction.
  • t=0t = 0. (a) gives 2∣Xi∣−3=ε≤12|X_i| - 3 = \varepsilon \le 1, so ∣Xi∣=2|X_i| = 2 and ε=1\varepsilon = 1: X2={a,b}X_2 = \{a, b\}, a single edge. □\square

Lemma 5 (a separation pair exists). A TD Laman graph H=(P,F)H = (P, F) with ∣P∣≥4|P| \ge 4 has a separation pair.

Proof. Take the three sets of Lemma 1. Since ∣P∣=∣A∣+∣B∣+∣C∣−3≥4|P| = |A| + |B| + |C| - 3 \ge 4, one of them, say AA, has at least 3 points. Let A∩B={p}A \cap B = \{p\} and A∩C={q}A \cap C = \{q\}. An edge from x∈A∖{p,q}x \in A \setminus \{p, q\} to y∉Ay \notin A would lie inside BB or CC, so xx would lie in A∩BA \cap B or A∩CA \cap C, which is false. So no edge leaves A∖{p,q}A \setminus \{p, q\}, which is not empty, in the graph on P∖{p,q}P \setminus \{p, q\}, and this graph also holds r∉Ar \notin A. So {p,q}\{p, q\} is a separation pair. □\square

Theorem 1 (the decomposition). For a Laman graph GG with n≥3n \ge 3 points, OWEN-DECOMPOSE returns a tree, for every choice of separation pairs in line L3 and of components in line L5, if and only if GG is TD. A tree has n−2n - 2 leaves.

Proof. By induction on the number of points. A Laman graph with 3 points is a triangle, which is TD, and line L2 returns a leaf. Let ∣P∣≥4|P| \ge 4. If HH is TD, Lemma 5 gives a separation pair, so line L3 finds one; by Lemma 2 both sides are smaller Laman graphs, by Lemma 4 both are TD, and by induction both calls return trees. If HH is not TD, either line L4 returns FAIL, or by Lemma 4 one side is not TD, its call returns FAIL by induction, and so does the whole call. Each split turns a part with 2k−32k - 3 edges into parts with 2k−22k - 2 edges in total, so the leaves have 2n−3+s2n - 3 + s edges for ss splits, and s=L−1s = L - 1 for LL leaves; then 3L=2n−3+L−13L = 2n - 3 + L - 1 gives L=n−2L = n - 2. □\square

Theorem 2 (the solve). Let GG be TD with positive lengths, and let OWEN-SOLVE run on its tree.

  1. If no leaf fails in line L8, the output satisfies every constraint.
  2. Let yy be a solution with y(a)≠y(b)y(a) \ne y(b) for every virtual edge abab of the tree. With the sign of each leaf (u,v,w)(u, v, w) taken from ORIENT(y(u),y(v),y(w))\mathrm{ORIENT}(y(u), y(v), y(w)), 0 counting as +1+1, no leaf fails, and the output is properly congruent to yy.
  3. If the lengths are measured on an integer draft x^\hat x and no leaf triangle is flat in x^\hat x, the output is properly congruent to x^\hat x. Every solution as in part 2 comes from one of the 2n−22^{n-2} sign vectors.

Proof. A virtual edge made at a split lies only in the second side, so line L10 sets its length before any part that holds it is solved. By induction over the tree, each part is placed so that its edges hold with these lengths. A leaf holds its three lengths by line L8. At a split, X1X_1 satisfies F1F_1; X2X_2 satisfies F2F_2 and abab, with d(ab)=∣X1(a)−X1(b)∣d(ab) = \lvert X_1(a) - X_1(b) \rvert if abab is virtual and the given length, which X1X_1 also satisfies, if it is real. So ∣X2(a)−X2(b)∣=∣X1(a)−X1(b)∣\lvert X_2(a) - X_2(b) \rvert = \lvert X_1(a) - X_1(b) \rvert, the proper motion of line L11 takes X2(a)X_2(a) and X2(b)X_2(b) exactly to X1(a)X_1(a) and X1(b)X_1(b), and it keeps the distances in X2X_2. The two sides share only aa and bb, so every edge of F1∪F2F_1 \cup F_2 holds, which proves part 1.

For part 2, show by induction that each part is placed properly congruent to yy on its points. A leaf: the points y(u)y(u), y(v)y(v), y(w)y(w) have the leaf's lengths, which are positive since yy keeps the ends of virtual edges apart, so line L8 places uu and vv by a proper motion of yy, and of the two points at the right distances from them it takes the one on the side of the sign of yy; if the triangle is flat, there is only one. A split: X1X_1 is properly congruent to yy on P1P_1, so the measured length of a virtual abab is ∣y(a)−y(b)∣\lvert y(a) - y(b) \rvert, the lengths of the second side are those of yy, and X2X_2 is properly congruent to yy on P2P_2 by induction. A proper motion is fixed by the images of two distinct points, so the motion of line L11 is the one that composes the two congruences, and the glued placement is properly congruent to yy on PP.

Part 3 is part 2 with y=x^y = \hat x, whose virtual edges have positive length since no leaf is flat, and whose signs line L8 computes exactly from the integer coordinates. A tree has n−2n - 2 leaves by Theorem 1. □\square

Theorem 3 (running time). With a separation pair search that takes time linear in the size of a part, OWEN-DECOMPOSE and OWEN-SOLVE take O(n2)O(n^2) time.

Proof. By Theorem 1 the tree has n−2n - 2 leaves and n−3n - 3 splits, and each part has at most nn points and 2n−32n - 3 edges, so the parts have O(n2)O(n^2) points and edges in total. Lines L1 to L7 take time linear in the size of the part, given a linear-time pair search. Each leaf of OWEN-SOLVE costs O(1)O(1), and each glue moves at most nn points. ■\blacksquare

Complexity

  • The tree. A split of a part with kk points gives parts with k1+k2=k+2k_1 + k_2 = k + 2 points and one edge more in total. So a decomposition has n−2n - 2 leaves and n−3n - 3 splits, and every part has at most nn points: the parts have O(n2)O(n^2) points and edges in total.
  • The analysis. With a linear-time search for a separation pair, each part costs time linear in its size, and the decomposition takes O(n2)O(n^2) time. This matches the quadratic bound in Owen's paper. The implementation finds a pair by kk runs of the articulation point search, O(k2)O(k^2) per part, so it takes O(n3)O(n^3) time.
  • The solve. Each leaf is O(1)O(1) work with one square root. Each glue moves the points of the second side, at most nn, so the solve takes O(n2)O(n^2) time.
  • Space. The tree and its parts take O(n2)O(n^2) space as stored here; storing each part only by its split pair and children brings this to O(n)O(n).

Properties

  • Exact analysis. The decomposition uses only the graph, so it holds for all values of the lengths.
  • Same class as the bottom-up method. It decomposes exactly the triangle-decomposable graphs, the class of the Fudos-Hoffmann reduction.
  • Quadratic equations only. Each leaf solves one quadratic equation over the field of the earlier values, so the solution is ruler-and-compass constructible, and the coordinates lie in an extension of degree at most 2n−22^{n-2}.
  • It stops at the right place. By the theorem of Owen and Power, a generic 3-connected Laman graph with more than 3 points has coordinates that are not solvable by radicals. So the parts where line L4 fails are, for generic lengths, exactly those that no method with square roots, or radicals of any order, can solve.
  • Recursive. The two sides are independent once ∣ab∣\lvert ab \rvert is known, so the recursion is natural, and the two sides of a split can be solved in parallel after the rigid side.

Variants and improvements

  • All pairs at once. Owen computes the triconnected components of the graph in one pass with the algorithm of Hopcroft and Tarjan, and treats each component with its virtual edges as one part. The split at one pair at a time is the same idea, one cut per step.
  • Points, lines, distances and angles. Owen's graphs have points and lines as vertices, each with 2 freedoms, and distances and angles as edges, each of weight 1. A part made only of lines with angles needs care, because angles fix only directions.
  • Bottom-up form. The Fudos-Hoffmann reduction merges clusters from the leaves, and finds the same plan in the other direction.
  • General parts. A DR-plan accepts any rigid part as a node, not only triangles, so a 3-connected part such as the prism becomes one node for a numerical or algebraic solver.
  • Under-constrained sketches. When a sketch has too few constraints, the method can add virtual edges to complete it, which shows the user which dimensions are still free.

When to use it

  • To analyze a planar sketch top-down, with the cut points visible, so that each part of the sketch is solved and changed separately.
  • To get an exact solution by square roots and to choose it by the orientations of the draft.
  • To check, in linear time per split, that a sketch can be solved by ruler and compass.

Do not use it alone for sketches with 3-connected parts, such as the prism or K3,3K_{3,3}: pass these parts to a general solver inside a DR-plan. Do not use it in space, where two points do not fix a part.

Pitfalls

  • Solving the wrong side first (line L6). If line L6 does not swap the sides, the side with one edge too few is solved first, and ∣ab∣\lvert ab \rvert is not fixed there. In the example, at the pair {0,5}\{0, 5\} the side {0,1,5}\{0, 1, 5\} has only 0101 and 1515, so ∣05∣\lvert 05 \rvert is free; the solver would measure a length that has nothing to do with the constraints.
  • Forgetting the virtual edge (line L7). Without abab the second side has 2k−42k - 4 edges, line L1 rejects it, or a solver accepts a part that can still flex.
  • The given length for a virtual edge (line L10). The length of a virtual edge must be measured on the solved rigid side. Taking it from the draft is wrong as soon as the dimensions differ from the draft, and the glue of line L11 then cannot match both aa and bb.
  • A mirror in the glue (line L11). A motion that matches aa and bb but may reflect, such as a best-fit transform, can mirror the second side and destroy the orientations that its leaves chose. Use the rotation and translation fixed by the two points.
  • The sign in floating point (line L8). A floating-point orientation of a nearly flat draft triangle can have the wrong sign and mirror a leaf. Compute it exactly.

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.

owen_triconnected_decomposition.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/owen-triconnected-decomposition/. The authors are listed in prov/AM42WY.jsonl.

"""Owen's top-down decomposition, for points and distances in the plane.

The constraint graph is split at a separation pair {a, b}. One side is rigid; the other
side gets a virtual edge ab and is rigid with it. Both sides are split again, until
every part is a triangle. The solver places the rigid side first, measures |ab| there,
places the other side with that length, and glues the two by a proper rigid motion.
"""

from math import sqrt

Edge = tuple[int, int]
# A node is ("tri", u, v, w) or ("split", a, b, rigid child, flexible child).
Node = tuple


def _key(u: int, v: int) -> Edge:
    return (u, v) if u < v else (v, u)


def _articulation_points(verts: list[int], adj: dict[int, list[int]], skip: int) -> list[int]:
    """Articulation points of the graph on verts minus skip, by an iterative low-point DFS.
    Raises ValueError if that graph is not connected. Cost O(n + m)."""
    rest = [v for v in verts if v != skip]
    root = rest[0]
    disc = {root: 0}
    low = {root: 0}
    parent = {root: -1}
    cut: set[int] = set()
    root_children = 0
    stack = [(root, iter(adj[root]))]
    t = 1
    while stack:
        v, it = stack[-1]
        advanced = False
        for w in it:
            if w == skip:
                continue
            if w not in disc:
                disc[w] = low[w] = t
                t += 1
                parent[w] = v
                if v == root:
                    root_children += 1
                stack.append((w, iter(adj[w])))
                advanced = True
                break
            if w != parent[v]:
                low[v] = min(low[v], disc[w])
        if advanced:
            continue
        stack.pop()
        if stack:
            u = stack[-1][0]
            low[u] = min(low[u], low[v])
            if u != root and low[v] >= disc[u]:
                cut.add(u)
    if len(disc) != len(rest):
        raise ValueError("the constraint graph is not 2-connected, so it is not rigid")
    if root_children >= 2:
        cut.add(root)
    return sorted(cut)


def separation_pair(verts: list[int], edges: set[Edge]) -> tuple[int, int] | None:
    """A pair {a, b} whose removal disconnects the graph, or None if there is none.
    Precondition: the graph is 2-connected with at least 4 vertices. Cost O(n (n + m))."""
    adj: dict[int, list[int]] = {v: [] for v in verts}
    for u, v in sorted(edges):
        adj[u].append(v)
        adj[v].append(u)
    for a in verts:
        cut = _articulation_points(verts, adj, a)
        if cut:
            return (a, cut[0])
    return None


def decompose(n: int, edges: list[Edge]) -> list[Node] | None:
    """Split the constraint graph (range(n), edges) at separation pairs, down to triangles.

    Precondition: the graph is a Laman graph (2n - 3 edges, and every k >= 2 vertices
    span at most 2k - 3 edges), n >= 3. Returns the list of nodes, root first, or None
    if a part with four or more vertices has no separation pair (the method fails).
    Raises ValueError if a count shows that the graph is not Laman.
    Cost: O(n^3) here; O(n^2) with a linear-time triconnectivity algorithm.
    """
    es = {_key(u, v) for u, v in edges}
    if len(es) != len(edges) or any(u == v for u, v in edges):
        raise ValueError("bad edges")
    nodes: list[Node] = [()]
    stack: list[tuple[int, list[int], set[Edge]]] = [(0, list(range(n)), es)]
    while stack:
        nid, verts, part = stack.pop()
        k = len(verts)
        if len(part) != 2 * k - 3:  # @line L1
            raise ValueError("a part has the wrong number of edges, so the graph is not Laman")
        if k == 3:  # @line L2
            nodes[nid] = ("tri", *verts)
            continue
        pair = separation_pair(verts, part)  # @line L3
        if pair is None:  # @line L4
            return None
        a, b = pair
        inside = set(verts) - {a, b}
        first = min(inside)
        comp = {first}
        todo = [first]
        nbr: dict[int, list[int]] = {v: [] for v in verts}
        for u, v in part:
            nbr[u].append(v)
            nbr[v].append(u)
        while todo:  # @line L5
            v = todo.pop()
            for w in nbr[v]:
                if w in inside and w not in comp:
                    comp.add(w)
                    todo.append(w)
        side1 = sorted(comp | {a, b})
        side2 = sorted((inside - comp) | {a, b})
        s1 = set(side1)
        ab = _key(a, b)
        e1 = {e for e in part if e[0] in s1 and e[1] in s1 and e != ab}
        e2 = {e for e in part if e not in e1 and e != ab}
        if ab in part:  # @line L6
            e1.add(ab)
        elif len(e2) == 2 * len(side2) - 3:
            side1, side2, e1, e2 = side2, side1, e2, e1
        e2.add(ab)  # @line L7
        i1, i2 = len(nodes), len(nodes) + 1
        nodes.extend(((), ()))
        nodes[nid] = ("split", a, b, i1, i2)
        stack.append((i2, side2, e2))
        stack.append((i1, side1, e1))
    return nodes


def is_decomposable(n: int, edges: list[Edge]) -> bool:
    """True if Owen's method splits the Laman graph down to triangles."""
    if n == 2 and len(edges) == 1:
        return True
    return decompose(n, edges) is not None


def orient(p: tuple[int, int], q: tuple[int, int], r: tuple[int, int]) -> int:
    """Sign of the orientation determinant of three integer points, computed exactly."""
    d = (q[0] - p[0]) * (r[1] - p[1]) - (q[1] - p[1]) * (r[0] - p[0])
    return (d > 0) - (d < 0)


def _triangle(l_uv: float, l_uw: float, l_vw: float, side: int) -> tuple[complex, complex, complex]:
    """Place u at 0, v on the positive x axis, and w on the side given by the sign."""
    if not (l_uv > 0.0 and l_uw > 0.0 and l_vw > 0.0):
        raise ValueError("lengths must be positive")
    x = (l_uv * l_uv + l_uw * l_uw - l_vw * l_vw) / (2.0 * l_uv)
    h2 = l_uw * l_uw - x * x
    if h2 < -1e-9 * max(l_uv, l_uw, l_vw) ** 2:
        raise ValueError("no real solution: the triangle inequality fails")
    h = sqrt(h2) if h2 > 0.0 else 0.0
    return 0j, complex(l_uv, 0.0), complex(x, h if side > 0 else -h)


def solve(
    n: int,
    lengths: dict[Edge, float],
    draft: list[tuple[int, int]] | None = None,
    signs: list[int] | None = None,
) -> list[tuple[float, float]]:
    """Place n points so that |p_u - p_v| = lengths[(u, v)] for every constraint.

    Precondition: the graph is a Laman graph that Owen's method splits into triangles,
    and the lengths are positive. Triangle i, in the order the solver meets them, takes
    signs[i] if given, else the exact orientation sign of its points in the integer
    draft (0 counts as +1). Raises ValueError if the method fails or a triangle has no
    real solution. Cost: the decomposition plus O(n^2) for the moves.
    """
    if n == 2 and len(lengths) == 1:
        ((u, v), d), = lengths.items()
        return [(0.0, 0.0), (d, 0.0)] if u == 0 else [(d, 0.0), (0.0, 0.0)]
    length = {_key(u, v): d for (u, v), d in lengths.items()}
    nodes = decompose(n, list(lengths))
    if nodes is None:
        raise ValueError("Owen's method fails: a part is 3-connected")
    leaves = sum(1 for nd in nodes if nd[0] == "tri")
    if signs is not None and len(signs) != leaves:
        raise ValueError("one sign per triangle is needed")
    placed: dict[int, dict[int, complex]] = {}
    leaf = 0
    stack: list[tuple[str, int]] = [("go", 0)]
    while stack:
        step, nid = stack.pop()
        nd = nodes[nid]
        if nd[0] == "tri":  # @line L8
            _, u, v, w = nd
            if signs is not None:
                side = signs[leaf]
            elif draft is not None:
                side = orient(draft[u], draft[v], draft[w]) or 1
            else:
                side = 1
            leaf += 1
            pu, pv, pw = _triangle(length[_key(u, v)], length[_key(u, w)], length[_key(v, w)], side)
            placed[nid] = {u: pu, v: pv, w: pw}
            continue
        _, a, b, i1, i2 = nd
        if step == "go":  # @line L9
            stack.append(("mid", nid))
            stack.append(("go", i1))
        elif step == "mid":  # @line L10
            r = placed[i1]
            length.setdefault(_key(a, b), abs(r[a] - r[b]))
            stack.append(("end", nid))
            stack.append(("go", i2))
        else:  # @line L11
            r, f = placed.pop(i1), placed.pop(i2)
            z = (r[b] - r[a]) / (f[b] - f[a])
            z /= abs(z)
            glued = dict(r)
            for v, x in f.items():
                glued.setdefault(v, r[a] + z * (x - f[a]))
            placed[nid] = glued
    final = placed[0]
    return [(final[v].real, final[v].imag) for v in range(n)]
test_owen_triconnected_decomposition.py 280 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/owen-triconnected-decomposition/. The authors are listed in prov/AM42WY.jsonl.

import random
from functools import lru_cache
from itertools import combinations
from math import sqrt

import pytest

from owen_triconnected_decomposition import decompose, is_decomposable, orient, separation_pair, solve

Edge = tuple[int, int]

EXAMPLE_EDGES = [(0, 1), (0, 2), (1, 2), (3, 4), (3, 5), (4, 5), (0, 3), (0, 4), (1, 5)]
EXAMPLE_DRAFT = [(0, 0), (6, 0), (3, -4), (-1, 5), (3, 6), (7, 4)]
PRISM = [(0, 1), (0, 2), (1, 2), (3, 4), (3, 5), (4, 5), (0, 3), (1, 4), (2, 5)]
K33 = [(u, v) for u in range(3) for v in range(3, 6)]


def laman(n: int, edges: list[Edge]) -> bool:
    """Brute force: 2n - 3 edges, and every k >= 2 vertices span at most 2k - 3 edges."""
    if len(edges) != 2 * n - 3:
        return False
    for s in range(1 << n):
        k = bin(s).count("1")
        if k >= 2 and sum(1 for u, v in edges if s >> u & 1 and s >> v & 1) > 2 * k - 3:
            return False
    return True


def components(verts: frozenset[int], edges: frozenset[Edge]) -> list[frozenset[int]]:
    left = set(verts)
    out = []
    while left:
        start = left.pop()
        comp = {start}
        todo = [start]
        while todo:
            v = todo.pop()
            for u, w in edges:
                for x, y in ((u, w), (w, u)):
                    if x == v and y in left:
                        left.discard(y)
                        comp.add(y)
                        todo.append(y)
        out.append(frozenset(comp))
    return out


def brute_pairs(verts: frozenset[int], edges: frozenset[Edge]) -> list[tuple[int, int]]:
    """Every pair whose removal disconnects the graph, by a search on each pair."""
    out = []
    for a, b in combinations(sorted(verts), 2):
        rest = verts - {a, b}
        inner = frozenset(e for e in edges if e[0] in rest and e[1] in rest)
        if len(components(rest, inner)) >= 2:
            out.append((a, b))
    return out


@lru_cache(maxsize=None)
def outcomes(verts: frozenset[int], edges: frozenset[Edge]) -> frozenset[bool]:
    """Brute force over every choice of separation pair and of the grouping of the
    pieces: the set of results (split to triangles or stuck) that the choices reach."""
    k = len(verts)
    if len(edges) != 2 * k - 3:
        return frozenset([False])
    if k == 3:
        return frozenset([True])
    res: set[bool] = set()
    pairs = brute_pairs(verts, edges)
    if not pairs:
        return frozenset([False])
    for a, b in pairs:
        ab = (min(a, b), max(a, b))
        rest = verts - {a, b}
        inner = frozenset(e for e in edges if e[0] in rest and e[1] in rest)
        comps = components(rest, inner)
        for r in range(1, len(comps)):
            for group in combinations(comps, r):
                s1 = frozenset().union(*group) | {a, b}
                s2 = (rest - s1) | {a, b}
                e1 = frozenset(e for e in edges if e[0] in s1 and e[1] in s1 and e != ab)
                e2 = frozenset(e for e in edges if e not in e1 and e != ab)
                if ab in edges:
                    e1 = e1 | {ab}
                elif len(e2) == 2 * len(s2) - 3:
                    s1, s2, e1, e2 = s2, s1, e2, e1
                e2 = e2 | {ab}
                o1, o2 = outcomes(s1, e1), outcomes(s2, e2)
                for x in o1:
                    for y in o2:
                        res.add(x and y)
    return frozenset(res)


def triangle_closure(n: int, edges: list[Edge]) -> bool:
    """Independent oracle by the bottom-up definition: the set R of vertex sets that are
    built from edges by gluing three members of R that pairwise share one point, at three
    different points. The graph is decomposable when the full set is in R."""
    r = {1 << u | 1 << v for u, v in edges}
    full = (1 << n) - 1
    grew = True
    while grew and full not in r:
        grew = False
        items = sorted(r)
        for i, x in enumerate(items):
            for j in range(i + 1, len(items)):
                y = items[j]
                xy = x & y
                if bin(xy).count("1") != 1:
                    continue
                for z in items[j + 1:]:
                    xz, yz = x & z, y & z
                    if bin(xz).count("1") == 1 and bin(yz).count("1") == 1 and len({xy, xz, yz}) == 3:
                        u = x | y | z
                        if u not in r:
                            r.add(u)
                            grew = True
    return full in r


def henneberg(n: int, rng: random.Random, type2: float) -> list[Edge]:
    edges = [(0, 1)]
    for v in range(2, n):
        if v >= 3 and rng.random() < type2:
            u, w = edges.pop(rng.randrange(len(edges)))
            x = rng.choice([t for t in range(v) if t not in (u, w)])
            edges += [(u, v), (w, v), (x, v)]
        else:
            u, w = rng.sample(range(v), 2)
            edges += [(u, v), (w, v)]
    return edges


def lengths_of(draft: list[tuple[int, int]], edges: list[Edge]) -> dict[Edge, float]:
    return {(u, v): sqrt((draft[u][0] - draft[v][0]) ** 2 + (draft[u][1] - draft[v][1]) ** 2) for u, v in edges}


def check_solution(pts: list[tuple[float, float]], lengths: dict[Edge, float]) -> None:
    scale = max(lengths.values())
    for (u, v), d in lengths.items():
        got = sqrt((pts[u][0] - pts[v][0]) ** 2 + (pts[u][1] - pts[v][1]) ** 2)
        assert abs(got - d) <= 1e-7 * scale


def check_congruent(pts: list[tuple[float, float]], draft: list[tuple[int, int]]) -> None:
    """Pairwise distances and signed areas agree with the draft, within a tolerance."""
    n = len(draft)
    scale = max(abs(c) for p in draft for c in p) + 1
    for u, v in combinations(range(n), 2):
        dd = (draft[u][0] - draft[v][0]) ** 2 + (draft[u][1] - draft[v][1]) ** 2
        dp = (pts[u][0] - pts[v][0]) ** 2 + (pts[u][1] - pts[v][1]) ** 2
        assert abs(dd - dp) <= 1e-6 * scale * scale
    for u, v, w in combinations(range(n), 3):
        exact = (draft[v][0] - draft[u][0]) * (draft[w][1] - draft[u][1]) - (draft[v][1] - draft[u][1]) * (draft[w][0] - draft[u][0])
        approx = (pts[v][0] - pts[u][0]) * (pts[w][1] - pts[u][1]) - (pts[v][1] - pts[u][1]) * (pts[w][0] - pts[u][0])
        assert abs(exact - approx) <= 1e-6 * scale * scale


def random_draft(n: int, rng: random.Random) -> list[tuple[int, int]]:
    pts: set[tuple[int, int]] = set()
    while len(pts) < n:
        pts.add((rng.randint(-20, 20), rng.randint(-20, 20)))
    out = list(pts)
    rng.shuffle(out)
    return out


def leaves(nodes: list) -> list[tuple[int, int, int]]:
    return [nd[1:] for nd in nodes if nd[0] == "tri"]


def test_example() -> None:
    nodes = decompose(6, EXAMPLE_EDGES)
    assert nodes is not None
    assert nodes[0][:3] == ("split", 0, 1)
    assert len(leaves(nodes)) == 4
    lengths = lengths_of(EXAMPLE_DRAFT, EXAMPLE_EDGES)
    pts = solve(6, lengths, EXAMPLE_DRAFT)
    check_solution(pts, lengths)
    check_congruent(pts, EXAMPLE_DRAFT)


def test_edge_cases() -> None:
    assert is_decomposable(2, [(0, 1)])
    assert is_decomposable(3, [(0, 1), (1, 2), (0, 2)])
    assert decompose(6, PRISM) is None
    assert decompose(6, K33) is None
    with pytest.raises(ValueError):
        decompose(4, list(combinations(range(4), 2)))
    with pytest.raises(ValueError):
        solve(3, {(0, 1): 1.0, (1, 2): 1.0, (0, 2): 3.0})
    with pytest.raises(ValueError):
        solve(6, lengths_of(EXAMPLE_DRAFT, PRISM))


def test_separation_pairs_against_search() -> None:
    rng = random.Random(3)
    for _ in range(300):
        n = rng.randint(4, 9)
        edges = henneberg(n, rng, 0.4)
        verts = list(range(n))
        es = {(min(u, v), max(u, v)) for u, v in edges}
        got = separation_pair(verts, es)
        brute = brute_pairs(frozenset(verts), frozenset(es))
        if got is None:
            assert brute == []
        else:
            assert (min(got), max(got)) in brute


def test_all_laman_graphs_up_to_six_points() -> None:
    """On every Laman graph with n <= 6: every choice of pairs gives the same result, the
    method agrees with it, and with the bottom-up triangle closure. On six points the
    graphs that are not decomposable are the 10 labelings of K33 and the 60 of the prism."""
    total = 0
    counts = {True: 0, False: 0}
    for n in range(3, 7):
        pairs = list(combinations(range(n), 2))
        for chosen in combinations(range(len(pairs)), 2 * n - 3):
            edges = [pairs[i] for i in chosen]
            if not laman(n, edges):
                continue
            total += 1
            res = outcomes(frozenset(range(n)), frozenset(edges))
            assert len(res) == 1
            (truth,) = res
            assert is_decomposable(n, edges) == truth
            assert triangle_closure(n, edges) == truth
            counts[truth] += 1
    assert total == 1 + 6 + 100 + 3355
    assert counts[False] == 70


def test_random_graphs_against_oracles() -> None:
    """500 random Laman graphs with 4 to 9 points: decomposable exactly when the closure
    says so; then the solution meets every constraint and matches the draft."""
    rng = random.Random(99)
    seen = {True: 0, False: 0}
    for _ in range(500):
        n = rng.randint(4, 9)
        edges = henneberg(n, rng, 0.5)
        rng.shuffle(edges)
        truth = triangle_closure(n, edges)
        seen[truth] += 1
        nodes = decompose(n, edges)
        assert (nodes is not None) == truth
        if n <= 7:
            es = frozenset((min(u, v), max(u, v)) for u, v in edges)
            assert outcomes(frozenset(range(n)), es) == frozenset([truth])
        if nodes is None:
            continue
        assert len(leaves(nodes)) == n - 2
        draft = random_draft(n, rng)
        lengths = lengths_of(draft, edges)
        pts = solve(n, lengths, draft)
        check_solution(pts, lengths)
        check_congruent(pts, draft)
    assert seen[True] > 100 and seen[False] > 10


def test_every_root_of_a_triangle_strip() -> None:
    rng = random.Random(8)
    for n in range(3, 8):
        edges = [(i, i + 1) for i in range(n - 1)] + [(i, i + 2) for i in range(n - 2)]
        draft = random_draft(n, rng)
        while any(orient(draft[i], draft[i + 1], draft[i + 2]) == 0 for i in range(n - 2)):
            draft = random_draft(n, rng)
        lengths = lengths_of(draft, edges)
        shapes = set()
        for bits in range(1 << (n - 2)):
            signs = [1 if bits >> i & 1 else -1 for i in range(n - 2)]
            pts = solve(n, lengths, signs=signs)
            check_solution(pts, lengths)
            z0 = complex(*pts[0])
            rot = (complex(*pts[1]) - z0) / abs(complex(*pts[1]) - z0)
            shapes.add(tuple((round(((complex(*p) - z0) / rot).real, 5), round(((complex(*p) - z0) / rot).imag, 5)) for p in pts))
        assert len(shapes) == 2 ** (n - 2)

History

Owen presented the method in 1991, at the first ACM Symposium on Solid Modeling Foundations and CAD/CAM Applications, as an algebraic method to place geometry from given distances and angles. He used the triconnected components algorithm that Hopcroft and Tarjan had published in 1973, and he showed that the decomposed systems need only quadratic equations, with a solution in an extension of degree a power of 2. The bottom-up method of Bouma, Fudos and Hoffmann followed a few years later, and in 2002 Joan-Arinyo, Soto-Riera, Vila-Marta and Vilaplana-Pastó proved that the two methods decompose the same class of graphs. Owen and Power proved in 2007 that the 3-connected parts where the method stops are, for generic lengths, not solvable by radicals.

References

  1. John C. Owen, Algebraic solution for geometry from dimensional constraints, ACM Symposium on Solid Modeling Foundations and CAD/CAM Applications (SMA '91), 397 to 407, 1991, the decomposition of the constraint graph at separation pairs with virtual edges, the use of the triconnected components algorithm, the solution by quadratic equations and the quadratic running time (general locator)
  2. John E. Hopcroft and Robert E. Tarjan, Dividing a graph into triconnected components, SIAM Journal on Computing 2(3), 135 to 158, 1973, the linear-time algorithm for separation pairs and triconnected components, with virtual edges (general locator)
  3. Robert Joan-Arinyo, Antoni Soto-Riera, Sebastià Vila-Marta and Josep Vilaplana-Pastó, Revisiting decomposition analysis of geometric constraint graphs, ACM Symposium on Solid Modeling and Applications (SM '02), 105 to 115, 2002, the proof that Owen's top-down analysis and the bottom-up reduction of Fudos and Hoffmann decompose the same class of graphs (general locator)
  4. Robert Joan-Arinyo, Antoni Soto-Riera, Sebastià Vila-Marta and Josep Vilaplana-Pastó, Revisiting decomposition analysis of geometric constraint graphs, Computer-Aided Design 36(2), 123 to 140, 2004, the journal version of the comparison of the top-down and bottom-up analyses (general locator)
  5. J. C. Owen and S. C. Power, The non-solvability by radicals of generic 3-connected planar Laman graphs, Transactions of the American Mathematical Society 359(5), 2269 to 2303, 2007, the main theorem, which shows that the 3-connected parts where the method stops need more than square roots (general locator)

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