Algorithm Search⌘K

Algorithmresearch

Support-free decomposition for multi-axis printing

Also called multi-axis 3D printing planning.

Splits a model by planar cuts into parts that each print without support in their own build direction, and orders them so a printer that can turn the part needs no supports.

Time
O(m w h n log n) beamO((5 h)^m n) exhaustive
Space
O(w h n) extra
Where
h = largest number of layers in one direction; m = largest number of cuts; n = number of voxels; w = beam width
Properties
deterministicnot exactiterative
Origin
Chenming Wu, Chengkai Dai, Guoxin Fang, Yong Jin Liu, Charlie C. L. Wang, 2017

A printer that can turn the part, such as a robot arm or a five-axis table, can build different regions of a model in different directions. A region that overhangs in the vertical direction may grow sideways from a wall that is already printed, with no support at all. Support-free decomposition splits the model into parts and gives each part a build direction and a place in the print order, so that every part is free of overhangs in its own direction, given the parts that are already there. This page uses the planar version of Wu, Dai, Fang, Liu and Wang (RoboFDM, 2017, and the general form with a beam-guided search): peel parts off the model with planes, and print them in the reverse order. On a voxel model the overhang test is exact, so a plan that the search returns is proved to print with no support and, under a simple model of the print head, with no collision. The search for the fewest parts is a combinatorial search with no known efficient exact method, so the beam search is a heuristic, and its quality on this page is measured against exhaustive search on small models.

In plain words

A normal printer always builds upward. A shelf that sticks out from a wall has nothing under it, so the printer needs props there. If the part can be turned on its side, the shelf can grow out of the wall, layer by layer, and each new layer rests on the one before it.

So the plan is: cut the model into a few pieces. Print the bottom piece the usual way. Then turn the part and print the next piece, which grows out of what is already there. The trick is to choose the cuts and the order so that no piece ever hangs in the air, and the nozzle never runs into the part.

The problem

The model is a set VV of integer voxels (x,y,z)(x, y, z) with z≥0z \ge 0, and the platform lies under z=0z = 0. The build directions are D={+z,+x,−x,+y,−y}D = \{+z, +x, -x, +y, -y\}. The direction −z-z is left out, because the part stands on the platform and the head cannot come from below it. In direction dd the layer of a voxel vv is ⟨v,d⟩\langle v, d \rangle.

The overhang rule. The support block S(v,d)S(v, d) is the set of the 9 voxels one layer below vv in direction dd: the voxel right under it and the 8 around that one. A voxel printed in direction dd can be deposited only if one voxel of S(v,d)S(v, d) is already solid, or d=+zd = +z and vv is on the platform. Each layer can stick out by one voxel per layer, which is the 45° rule of material extrusion on the voxel grid (see support structure generation for where the angle comes from).

The head rule. While layer ℓ\ell in direction dd is printed, the head occupies the half-space ⟨p,d⟩>ℓ\langle p, d \rangle > \ell, and no printed voxel may be there.

Planar cuts. From a region RR, a cut in direction dd at level cc removes the part P={v∈R:⟨v,d⟩≥c}P = \{v \in R : \langle v, d \rangle \ge c\}. The cut is support-free if every voxel of PP has a voxel of RR in its support block. Let U(R,d)U(R, d) be the voxels of RR with no voxel of RR in their support block. A plan is a sequence of support-free cuts V=R0⊃R1⊃⋯⊃RmV = R_0 \supset R_1 \supset \dots \supset R_m whose last region, the base, has U(Rm,+z)=∅U(R_m, +z) = \emptyset. The task is to find a plan with few parts.

The algorithm

The test for one cut is cheap. The cut (d,c)(d, c) is support-free exactly when cc is above every layer of U(R,d)U(R, d), because the condition on a voxel of PP does not depend on cc. So one pass over RR gives all the support-free cuts in a direction. The search over sequences is a beam search that keeps the ww best regions after each round.

  1. DECOMPOSE(V, w, m)
  2. 1beam ← {(V, empty sequence)}
  3. 2for round = 0 to m do
  4. 3if some (R, s) in beam has U(R, +z) = ∅ then return PLAN(R, s)
  5. 4children ← empty map from regions to sequences
  6. 5for each (R, s) in beam and each direction d in D do
  7. 6ℓ ← max{⟨v, d⟩ : v ∈ U(R, d)} ▷ −∞ if U is empty
  8. 7for each level c of R with c > ℓ and c > min level do
  9. 8P ← {v ∈ R : ⟨v, d⟩ ≥ c}; children[R \ P] ← s + (d, P)
  10. 9beam ← the w children with the fewest base overhangs |U(R \ P, +z)|, larger regions first
  11. 10return failure
  12. PLAN(R, s)
  13. 11return (+z, R), then the parts of s in reverse order

Line L3 stops as soon as some region can be the base: it prints upward and has no overhang. Lines L6 to L8 list every support-free cut of RR. Line L9 is the heuristic: it ranks the regions by the number of voxels that still hang in the vertical direction, and on a tie it keeps the region with more voxels, which leaves more material to support later cuts. Equal regions reached by different sequences are merged, because what can be cut next depends only on the region. Line L11 reverses the order: the last cut leaves the base, which is printed first, and the first part cut off is printed last.

For small models the same expansion can be run as a breadth first search over all regions, with no beam. It finds the least number of parts over all plans of planar cuts, and the tests use it as the reference.

Example

A T-shaped model has a column of 2×22 \times 2 voxels, 6 voxels tall (x∈{0,1}x \in \{0, 1\}, y∈{0,1}y \in \{0, 1\}, 0≤z≤50 \le z \le 5), and two arms at the top (z∈{4,5}z \in \{4, 5\}), each 4 voxels long, from x=−4x = -4 to −1-1 and from x=2x = 2 to 55. It has 56 voxels.

In +z+z, the arm voxels at z=4z = 4 with x=−1x = -1 and x=2x = 2 are held by the column voxels at z=3z = 3, diagonally, which is the 45° rule. The 12 voxels at z=4z = 4 with x∈{−4,−3,−2,3,4,5}x \in \{-4, -3, -2, 3, 4, 5\} have nothing below them, so U(V,+z)U(V, +z) has 12 voxels and VV is not a base.

The cuts of VV in each direction, from lines L6 to L8:

direction highest layer in UU valid levels cc part sizes
+z+z 4 (z=4z = 4) 5 20
+x+x 0 (column voxels at x=0x = 0, z≤2z \le 2) 1 to 5 28, 16, 12, 8, 4
−x-x −1-1 (column voxels at x=1x = 1, z≤2z \le 2) 0 to 4 28, 16, 12, 8, 4
+y+y, −y-y the first of the two layers one level 28

In +x+x the voxels at x=−4x = -4 have nothing to their left, and the lower column voxels at x=0x = 0 have nothing at x=−1x = -1, because the left arm is only at z≥4z \ge 4. So the cut must be at c≥1c \ge 1. Round 1 ranks the children by their remaining overhangs. The cut (+x,3)(+x, 3) removes the right arm beyond x=2x = 2 (12 voxels) and leaves 6 overhanging voxels, and so does (−x,2)(-x, 2) on the left. The tie goes to the larger region and then to a fixed order. Round 2 cuts the other arm. Now the region is the column with one voxel of each arm, 32 voxels, with no overhang, and line L3 returns it.

print order direction voxels what it is
1 +z+z 32 column, and the arm voxels at x=−1x = -1 and x=2x = 2
2 −x-x 12 left arm, −4≤x≤−2-4 \le x \le -2, grown leftward from x=−1x = -1
3 +x+x 12 right arm, 3≤x≤53 \le x \le 5, grown rightward from x=2x = 2

The breadth first search confirms that 3 parts is the least for this model: each arm needs its own direction, and the base must exist. A gallows with one arm needs 2 parts. A rod of two voxels that hangs under the end of an arm has no plan at all: the lower voxel touches only the voxel above it, so it has no support in any allowed direction.

Measured quality. On 400 random models in a 5×2×55 \times 2 \times 5 box (each voxel present with probability 1/2, seed 7), 374 have a plan with at most 4 parts. Beam width 4 found a plan with the least number of parts on all 374. Width 1 (a greedy search) needed more parts or found no plan within 3 cuts on 3 of them. These are measurements on this test set, not a bound.

Correctness

Three statements are proved. First, the cut (d,c)(d, c) is support-free exactly when cc is above the top layer of U(R,d)U(R, d), so lines L6 to L8 list all the support-free cuts and no others. Second, the test is exact for the model: if a voxel vv of the part has no voxel of RR in its support block, no print order can deposit it, because only voxels of the model are ever solid. Third, every plan prints. Print the base by increasing zz: each voxel off the platform has a voxel of the base one layer lower in its block. Then print each part PiP_i by increasing layer, when exactly Ri+1=Ri∖PiR_{i+1} = R_i \setminus P_i is solid. A voxel of PiP_i at layer ℓ\ell has a voxel ww of RiR_i at layer ℓ−1\ell - 1 in its block, and ww is either in Ri+1R_{i+1}, which is printed, or in PiP_i at a lower layer, which was printed just before. Every voxel of Ri+1R_{i+1} has layer less than ci≤ℓc_i \le \ell, so no printed voxel is in the half-space of the head. By induction the whole model is printed, each voxel once.

The beam search is not complete: it can return failure when a plan exists. The breadth first search is complete up to its limit. The full proof is in the correctness proof.

What the tests check. They print each plan voxel by voxel with an independent check of the support blocks and the head half-space, compare the beam result with the exhaustive minimum on random models, and check that a wrong order, a missing part or a single upward print is rejected.

Proof: A plan of support-free planar cuts prints every voxel with support and without head collision, and the cut test is exact for the voxel modelfull

Setting. The model is a finite set V⊂Z3V \subset \mathbb Z^3 of voxels with z≥0z \ge 0. The directions are D={+z,+x,−x,+y,−y}D = \{+z, +x, -x, +y, -y\}, unit vectors of the grid. For v∈Z3v \in \mathbb Z^3 and d∈Dd \in D the layer of vv is ⟨v,d⟩\langle v, d \rangle, and the support block S(v,d)S(v, d) is the set of the 9 voxels ww with ⟨w,d⟩=⟨v,d⟩−1\langle w, d \rangle = \langle v, d \rangle - 1 and max⁡i∣wi−vi∣≤1\max_i |w_i - v_i| \le 1.

The printing model has three rules.

  1. Support. A voxel vv printed in direction dd can be deposited only if a voxel of S(v,d)S(v, d) is already solid, or d=+zd = +z and vz=0v_z = 0 (the platform).
  2. Only the model. No material outside VV is printed, so at every moment the solid set is a subset of VV.
  3. Head. While a voxel at layer ℓ\ell of direction dd is deposited, the print head occupies the open half-space {p:⟨p,d⟩>ℓ}\{p : \langle p, d \rangle > \ell\}, and no solid voxel may be there. The platform is not an obstacle.

For a set RR and d∈Dd \in D let U(R,d)={v∈R:S(v,d)∩R=∅}U(R, d) = \{v \in R : S(v, d) \cap R = \emptyset\}, without the voxels with vz=0v_z = 0 when d=+zd = +z. A cut of RR is a pair (d,c)(d, c), with the part P={v∈R:⟨v,d⟩≥c}P = \{v \in R : \langle v, d \rangle \ge c\} and the rest R∖PR \setminus P. The cut is valid if P∩U(R,d)=∅P \cap U(R, d) = \emptyset and both PP and R∖PR \setminus P are nonempty. A plan is a sequence of valid cuts R0=VR_0 = V, Ri+1=Ri∖PiR_{i+1} = R_i \setminus P_i for i=0,…,m−1i = 0, \dots, m - 1, with a base RmR_m such that U(Rm,+z)=∅U(R_m, +z) = \emptyset. It is printed as RmR_m in +z+z, then Pm−1P_{m-1}, …, P0P_0, each part in the order of increasing layer.

Claim.

  1. (Valid cuts.) The cut (d,c)(d, c) of RR with nonempty part and rest is valid if and only if c>max⁡{⟨v,d⟩:v∈U(R,d)}c > \max\{\langle v, d \rangle : v \in U(R, d)\}, with the max of an empty set taken as −∞-\infty. Lines L6 to L8 list exactly the valid cuts.
  2. (Exactness of the test.) If P∩U(R,d)≠∅P \cap U(R, d) \ne \emptyset, then under rules 1 and 2 there is no order in which PP can be printed in direction dd while only R∖PR \setminus P is solid at the start and only voxels of RR are added.
  3. (Soundness.) Every plan prints all of VV under rules 1, 2 and 3, every voxel once.
  4. (Termination and optimality.) The beam search stops after at most m+1m + 1 rounds and returns a plan or failure. The breadth first search returns the least number of parts over all plans, when that number is at most its limit.

Proof of 1. The condition P∩U(R,d)=∅P \cap U(R, d) = \emptyset says that no voxel of U(R,d)U(R, d) has layer at least cc, that is, every voxel of U(R,d)U(R, d) has layer less than cc. This is c>max⁡v∈U(R,d)⟨v,d⟩c > \max_{v \in U(R, d)} \langle v, d \rangle. Line L6 computes this maximum, line L7 keeps the levels cc above it and above the lowest level of RR (so that the rest is not empty), and every level of RR at or below the top gives a nonempty part. A threshold that is not a level of RR gives the same part as the next level above it, so only levels need to be listed.

Proof of 2. Let v∈P∩U(R,d)v \in P \cap U(R, d). Then S(v,d)∩R=∅S(v, d) \cap R = \emptyset, and for d=+zd = +z also vz>0v_z > 0. By rule 2 the solid set at any moment is a subset of RR (the voxels already there, R∖PR \setminus P, and the voxels of PP added before vv). So no voxel of S(v,d)S(v, d) is ever solid when vv is deposited, and the platform does not help, so rule 1 fails for vv in every order.

Proof of 3. Induction over the print order.

The base. Print RmR_m in +z+z, by increasing zz. Let v∈Rmv \in R_m be deposited at layer ℓ=vz\ell = v_z. If vz=0v_z = 0 it rests on the platform. Otherwise v∉U(Rm,+z)v \notin U(R_m, +z), so some w∈S(v,+z)∩Rmw \in S(v, +z) \cap R_m exists, and wz=ℓ−1w_z = \ell - 1, so ww was deposited in an earlier layer. Rule 1 holds. The solid voxels at that moment are voxels of RmR_m of layers at most ℓ\ell, so none is in {z>ℓ}\{z > \ell\} and rule 3 holds.

A part. Assume that Ri+1R_{i+1} is printed. Print PiP_i in direction d=did = d_i by increasing layer. Let v∈Piv \in P_i at layer ℓ≥ci\ell \ge c_i. The cut is valid, so v∉U(Ri,d)v \notin U(R_i, d), and some w∈S(v,d)∩Riw \in S(v, d) \cap R_i exists, with ⟨w,d⟩=ℓ−1\langle w, d \rangle = \ell - 1. Either w∈Ri+1w \in R_{i+1}, which is solid, or w∈Piw \in P_i at a lower layer, which was deposited before vv. So rule 1 holds. The solid voxels at that moment are Ri+1R_{i+1} and voxels of PiP_i at layers at most ℓ\ell. Every voxel of Ri+1={u∈Ri:⟨u,d⟩<ci}R_{i+1} = \{u \in R_i : \langle u, d \rangle < c_i\} has layer less than ci≤ℓc_i \le \ell. So no solid voxel is in {⟨p,d⟩>ℓ}\{\langle p, d \rangle > \ell\}, and rule 3 holds. After PiP_i the solid set is Ri+1∪Pi=RiR_{i+1} \cup P_i = R_i.

After the last part the solid set is R0=VR_0 = V. The sets Rm,Pm−1,…,P0R_m, P_{m-1}, \dots, P_0 are disjoint, because each Pi⊆RiP_i \subseteq R_i and Ri+1=Ri∖PiR_{i+1} = R_i \setminus P_i, so every voxel is printed once. Only voxels of VV are printed, so rule 2 holds.

Proof of 4. Each valid cut has a nonempty part, so ∣Ri+1∣<∣Ri∣|R_{i+1}| < |R_i|, and each region has at most 5(h−1)5(h - 1) valid cuts, where hh is the largest number of levels in one direction. The beam has at most ww states, so each round makes finitely many children. The loop of line L2 runs at most m+1m + 1 times, and each round either returns at line L3 or replaces the beam. So the search stops. If it returns, the plan is made of valid cuts and a base with U(R,+z)=∅U(R, +z) = \emptyset, which is a plan in the sense above, so claim 3 applies to it. The breadth first search visits the regions reachable by kk valid cuts for k=0,1,2,…k = 0, 1, 2, \dots and stops at the first kk at which one of them is a base, so k+1k + 1 is the least number of parts. It merges equal regions, which is safe, because the validity of later cuts depends only on the region.

What is not proved. The beam search can miss a plan that exists, because it keeps only ww regions per round. Rule 3 is a model of the head: a real nozzle has a finite cone, a real printer has a frame and a platform, and the robot that turns the part needs its own collision check. The 45° rule of the support block is a property of the process and is not proved here.

Complexity

With a hash table of the voxels, U(R,d)U(R, d) takes 9 lookups per voxel, O(n)O(n) expected time. One region has at most h−1h - 1 cuts per direction, and building one part and its rest takes O(n)O(n). One round expands ww regions into at most 5wh5 w h children in O(whn)O(w h n), and scoring them takes O(n)O(n) each. The code sorts the children with the voxel list as a tie key, which adds a log⁡n\log n factor. So mm rounds take O(mwhnlog⁡n)O(m w h n \log n) time and O(whn)O(w h n) space for the children of one round.

The exhaustive search can visit (5h)m(5h)^m sequences in the worst case, so it is only for small models and few cuts. On the 5×2×55 \times 2 \times 5 test models the whole set of 400 runs in about a second in Python.

Properties

  • Sound. Every returned plan prints without support and without head collision, under the stated model.
  • Exact test, heuristic search. The support test for a cut is exact on voxels. The choice of cuts is a heuristic with no bound on the number of parts.
  • Only the region matters. What can be cut next depends only on the remaining region, not on how it was reached.
  • Planar parts. Each part is a half-space of the region, so the joints between parts are flat, and the head model holds automatically for planar cuts.
  • No guarantee of existence. Some models have no plan, for example a voxel whose only neighbor is directly above it.

Variants and improvements

  • Objectives. RoboFDM and its successors weigh the number of parts, the area of the remaining overhang, and the printing time. When no plan without supports exists, the remaining overhang is left to a few supports.
  • Continuous planes. The real method cuts a triangle mesh with planes of any normal, sampled on the sphere of directions, and tests the overhang of the faces. The voxel version of this page keeps the test exact.
  • Collision checks. A nozzle is a cone, not a half-space. Then a part is printable only if the cone at each point avoids the printed material, which is a question of accessibility cones and collision detection.
  • Curved layers. Dai and coauthors (2018) replace planar parts by curved layers that grow over the volume, so the build direction changes from point to point. See curved layer printing.
  • One fixed direction. When the printer cannot turn the part, the best single direction is the problem of build orientation.

When to use it

Use it for a robot arm or a five-axis printer when supports are costly: parts whose supports would be hard to remove, materials that do not have a soluble support, or surfaces that must stay clean. Models that branch, like trees, frames and brackets, often split into a few support-free parts. A closed box with a cavity does not split well: the roof of the cavity cannot grow upward, and in each sideways direction the far wall would have to grow across the cavity. The beam search with 4 cuts finds no plan for hollow cubes with sides 5, 7 and 8. On an ordinary three-axis printer the method does not apply.

Pitfalls

  • Forgetting the printed parts. A part is support-free only relative to the material printed before it. Testing each part alone, with nothing below it, rejects good plans.
  • Wrong order. The parts must be printed in the reverse of the cut order. In the order of the cuts, the first part has nothing to rest on.
  • Allowing −z-z. A part printed downward needs the head under the platform. Leave the direction out, or model the platform.
  • Ignoring the nozzle. The half-space head is a model. A real head with a carriage can hit the part even when the planar cut is clean, and a robot can hit itself.
  • Too narrow a beam. A greedy search (width 1) misses plans that a wider beam finds, as the measurements above show.
  • Weak joints. Parts that grow in different directions meet at a flat joint, and the strength across it is lower than inside a part.

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.

multi_axis_printing_decomposition.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/multi-axis-printing-decomposition/. The authors are listed in prov/N5ERYT.jsonl.

"""Support-free decomposition of a voxel model by planar cuts.

A model is a set of integer voxels (x, y, z) with z >= 0. The platform lies
under z = 0. A part P is printed in a direction d, layer by layer in the order
of <v, d>. A voxel v can be deposited when one voxel of its support block
S(v, d), the 3 x 3 block of voxels one layer below v, is already solid. In the
direction +z a voxel with z = 0 rests on the platform. This is a 45 degree
overhang rule on the voxel grid.

The search peels parts off the top: from the remaining set R it cuts
P = {v in R : <v, d> >= c}. Every voxel of P must have a support in R. The
remaining set after the last cut is the base, printed in +z. The parts are
printed in the reverse order of the cuts.
"""

DIRECTIONS = {"+z": (0, 0, 1), "+x": (1, 0, 0), "-x": (-1, 0, 0), "+y": (0, 1, 0), "-y": (0, -1, 0)}


def dot(v, d):
    return v[0] * d[0] + v[1] * d[1] + v[2] * d[2]


def support_block(v, d):
    """The 9 voxels one layer below v in the direction d."""
    axis = [i for i in range(3) if d[i] != 0][0]
    others = [i for i in range(3) if i != axis]
    below = list(v)
    below[axis] -= d[axis]
    out = []
    for a in (-1, 0, 1):
        for b in (-1, 0, 1):
            w = list(below)
            w[others[0]] += a
            w[others[1]] += b
            out.append(tuple(w))
    return out


def supported(v, d, solid):
    if d == (0, 0, 1) and v[2] == 0:
        return True  # the platform
    return any(w in solid for w in support_block(v, d))


def unsupported(region, d):
    """Voxels of the region with no support inside the region."""
    return [v for v in region if not supported(v, d, region)]


def is_base(region):
    return not unsupported(region, (0, 0, 1))


def cuts(region, name):
    """All valid planar cuts of the region in one direction (lines L6 to L8).

    The validity of P = {<v, d> >= c} only asks that every voxel of P has a
    support in the region, so the valid thresholds are all c above the top
    level of the unsupported voxels. A cut must leave a nonempty rest.
    """
    d = DIRECTIONS[name]
    levels = sorted({dot(v, d) for v in region})
    bad = unsupported(region, d)
    low = max((dot(v, d) for v in bad), default=None)  # @line L6
    out = []
    for c in levels:
        if (low is None or c > low) and c > levels[0]:  # @line L7
            part = frozenset(v for v in region if dot(v, d) >= c)
            out.append((name, c, part, region - part))  # @line L8
    return out


def score(region):
    """Smaller is better: unsupported voxels of the base, then fewer voxels cut."""
    return (len(unsupported(region, (0, 0, 1))), -len(region))


def beam_decompose(model, width=4, max_cuts=5):
    """Beam search over cut sequences. Return the plan or None.

    A plan is a list of (direction, voxels) in print order: the base first,
    with direction "+z".
    """
    beam = [(frozenset(model), [])]  # @line L1
    for level in range(max_cuts + 1):  # @line L2
        for region, seq in beam:
            if is_base(region):  # @line L3
                return plan_from(region, seq)
        if level == max_cuts:
            break
        children = {}  # @line L4
        for region, seq in beam:
            for name in DIRECTIONS:  # @line L5
                for d, c, part, rest in cuts(region, name):
                    if rest not in children:
                        children[rest] = seq + [(d, c, part)]
        ranked = sorted(children.items(), key=lambda kv: (score(kv[0]), sorted(kv[0])))
        beam = ranked[:width]  # @line L9
    return None  # @line L10


def plan_from(base, seq):
    """The base, then the parts in the reverse order of the cuts."""
    plan = [("+z", base)]  # @line L11
    for d, c, part in reversed(seq):
        plan.append((d, part))
    return plan


def exhaustive_min_parts(model, max_parts=4):
    """Breadth first search over all cut sequences. Return the least number
    of parts (base included) or None if more than max_parts are needed."""
    level = {frozenset(model)}
    seen = set(level)
    for k in range(1, max_parts + 1):
        if any(is_base(r) for r in level):
            return k
        nxt = set()
        for region in level:
            for name in DIRECTIONS:
                for _, _, _, rest in cuts(region, name):
                    if rest not in seen:
                        seen.add(rest)
                        nxt.add(rest)
        level = nxt
    return None


def simulate(model, plan):
    """Independent check of a plan, voxel by voxel.

    Print each part in its order, each part in increasing <v, d>. Every voxel
    must touch a solid voxel of its support block (or the platform), and no
    solid voxel may lie strictly above the current layer, which is where the
    print head is (half-space head model). Return (ok, message).
    """
    solid = set()
    seen = set()
    for name, part in plan:
        d = DIRECTIONS[name]
        if seen & set(part):
            return False, "parts overlap"
        seen |= set(part)
        for v in sorted(part, key=lambda v: dot(v, d)):
            layer = dot(v, d)
            ok = d == (0, 0, 1) and v[2] == 0
            for dx in (-1, 0, 1):
                for dy in (-1, 0, 1):
                    for dz in (-1, 0, 1):
                        w = (v[0] + dx, v[1] + dy, v[2] + dz)
                        if w in solid and dot(w, d) == layer - 1:
                            ok = True
            if not ok:
                return False, "overhang at %s in %s" % (v, name)
            if any(dot(w, d) > layer for w in solid):
                return False, "head collision at %s in %s" % (v, name)
            solid.add(v)
    if solid != set(model):
        return False, "parts do not cover the model"
    return True, "ok"


def gallows(arm=6, height=6, depth=2):
    """A column of 2 x depth voxels with an arm at the top that sticks out."""
    vox = set()
    for z in range(height):
        for x in range(2):
            for y in range(depth):
                vox.add((x, y, z))
    for z in range(height - 2, height):
        for x in range(2, 2 + arm):
            for y in range(depth):
                vox.add((x, y, z))
    return frozenset(vox)


def tee(arm=4, height=6, depth=2):
    """A column with arms on both sides at the top."""
    vox = set()
    for z in range(height):
        for x in range(2):
            for y in range(depth):
                vox.add((x, y, z))
    for z in range(height - 2, height):
        for x in list(range(-arm, 0)) + list(range(2, 2 + arm)):
            for y in range(depth):
                vox.add((x, y, z))
    return frozenset(vox)
test_multi_axis_printing_decomposition.py 103 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/multi-axis-printing-decomposition/. The authors are listed in prov/N5ERYT.jsonl.

import random

from multi_axis_printing_decomposition import (
    DIRECTIONS,
    beam_decompose,
    cuts,
    dot,
    exhaustive_min_parts,
    gallows,
    is_base,
    simulate,
    support_block,
    tee,
    unsupported,
)


def random_model(rng, p):
    return frozenset((x, y, z) for x in range(5) for y in range(2) for z in range(5) if rng.random() < p)


def test_support_block_is_the_layer_below() -> None:
    for d in DIRECTIONS.values():
        v = (3, -2, 5)
        block = support_block(v, d)
        assert len(set(block)) == 9
        assert all(dot(w, d) == dot(v, d) - 1 for w in block)
        assert all(max(abs(w[i] - v[i]) for i in range(3)) == 1 for w in block)


def test_tee_needs_three_parts() -> None:
    m = tee()
    assert len(m) == 56
    assert len(unsupported(m, (0, 0, 1))) == 12  # the arm undersides beyond the 45 degree rule
    plan = beam_decompose(m)
    assert [(d, len(p)) for d, p in plan] == [("+z", 32), ("-x", 12), ("+x", 12)]
    assert simulate(m, plan) == (True, "ok")
    assert exhaustive_min_parts(m) == 3


def test_gallows_needs_two_parts() -> None:
    m = gallows()
    plan = beam_decompose(m)
    assert [(d, len(p)) for d, p in plan] == [("+z", 28), ("+x", 20)]
    assert simulate(m, plan) == (True, "ok")
    assert exhaustive_min_parts(m) == 2


def test_every_cut_is_support_free_by_direct_test() -> None:
    rng = random.Random(11)
    for _ in range(80):
        m = random_model(rng, 0.6)
        for name, d in DIRECTIONS.items():
            for _, c, part, rest in cuts(m, name):
                assert part | rest == m and not (part & rest)
                assert all(dot(v, d) >= c for v in part) and all(dot(v, d) < c for v in rest)
                # direct overhang test: print rest, then part layer by layer
                assert simulate(m, [("+z", rest), (name, part)])[1] != "parts overlap"
                solid = set(rest)
                for v in sorted(part, key=lambda v: dot(v, d)):
                    assert any(w in solid for w in support_block(v, d))
                    solid.add(v)


def test_beam_plans_pass_the_print_simulation() -> None:
    rng = random.Random(7)
    found = 0
    for _ in range(200):
        m = random_model(rng, 0.5)
        if not m:
            continue
        best = exhaustive_min_parts(m, 4)
        plan = beam_decompose(m, width=4, max_cuts=3)
        if plan is None:
            assert best is None
            continue
        found += 1
        ok, msg = simulate(m, plan)
        assert ok, msg
        assert best is not None and len(plan) >= best
        assert len(plan) == best  # width 4 is enough on this test set
    assert found > 150


def test_simulation_rejects_bad_plans() -> None:
    m = tee()
    assert not simulate(m, [("+z", m)])[0]  # overhangs
    plan = beam_decompose(m)
    assert not simulate(m, list(reversed(plan)))[0]  # wrong order
    base, left, right = plan
    assert not simulate(m, [base, left])[0]  # does not cover the model


def test_a_hanging_voxel_has_no_plan() -> None:
    # a rod of two voxels hangs under the end of an arm. The lower voxel has
    # only one neighbor, directly above it, and -z is not allowed.
    m = frozenset({(0, 0, z) for z in range(4)} | {(x, 0, 3) for x in range(1, 4)} | {(3, 0, 2), (3, 0, 1)})
    assert not is_base(m)
    assert beam_decompose(m, width=8, max_cuts=4) is None
    assert exhaustive_min_parts(m, 5) is None

History

Multi-directional printing grew with robot arm printers in the 2010s. Wu, Dai, Fang, Liu and Wang presented RoboFDM at ICRA 2017: a robot arm holds the platform, the model is split by planes into parts that are support-free in their own directions, and the parts are printed in a collision-free order. Their later paper on a general support-effective decomposition (preprint 2018) represents the decomposition by a sequence of clipping planes and finds it by a beam-guided search, which also works for models with loops and handles. Dai, Wang, Wu, Lefebvre, Fang and Liu (SIGGRAPH 2018) went from planar parts to curved layers that cover the whole volume.

References

  1. Chenming Wu, Chengkai Dai, Guoxin Fang, Yong-Jin Liu and Charlie C. L. Wang, RoboFDM, a robotic system for support-free fabrication using FDM, IEEE International Conference on Robotics and Automation (ICRA), 2017, 1175 to 1180, the decomposition of a model by planes into parts that are support-free in their own directions, printed one after the other in a collision-free order by a robot arm that holds the part
  2. Chenming Wu, Chengkai Dai, Guoxin Fang, Yong-Jin Liu and Charlie C. L. Wang, General support-effective decomposition for multi-directional 3D printing, IEEE Transactions on Automation Science and Engineering (preprint 2018), the sequence of clipping planes found by a beam-guided search with manufacturing constraints, for models with loops and handles
  3. Chengkai Dai, Charlie C. L. Wang, Chenming Wu, Sylvain Lefebvre, Guoxin Fang and Yong-Jin Liu, Support-free volume printing by multi-axis motion, ACM Transactions on Graphics 37(4), 2018, Article 134, the decomposition of a volume into curved layers that are support-free and collision-free, and the tool paths on each layer for a multi-axis printer

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.beam
  • a full proof of time.exhaustive
  • 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