Algorithmcore
Iso-planar toolpath
Also called drive plane toolpath.
Machines a surface along its cuts by a family of parallel planes, which run across patch boundaries, but the spacing on the surface grows where the surface is steep.
- Solves
- Toolpath planning
- Time
- O(K 2^m) worst
- Space
- O(m) extra
- Where
- K = number of drive planes; m = depth limit of the chord refinement
- Model
- Real RAM
- Properties
- deterministicexactrecursive
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Yunching Huang, James H. Oliver, 1994
An iso-planar toolpath machines a surface along the curves where it meets a family of parallel drive planes, , one pass per plane. Seen from above, the passes are straight and evenly spaced, as in a direction-parallel path, but in space they follow the surface. The planes do not care how the surface is cut into patches, so one pass runs across many patches. The cost is that the spacing on the surface is not the spacing of the planes: where the surface climbs steeply along , the passes lie farther apart on it. This is a manufacturing method of mechanical CAD: placement and routing here mean where a cutter goes and how it moves, not the placement and routing of a circuit. The code cuts a bilinear patch with exact rational points and a recursive chord refinement.
In plain words
Slice a loaf of bread with evenly spaced cuts. Each cut leaves a curve on the crust. An iso-planar path moves the tool along these curves, one after the other.
On the flat top of the loaf the curves are as far apart as the cuts. On the steep ends of the loaf the cuts still go straight down at the same spacing, but the crust is tilted, so the curves on the crust are farther apart than the cuts. A tool that leaves a smooth finish on top leaves ridges on the steep parts.
Each curve is drawn as a chain of short straight pieces. A piece is split when the curve bends too far away from it.
The problem
The input is a surface, a plane spacing and a chord tolerance . The output is a set of passes, one for each plane that meets the surface, each a polyline of cutter contact points on the surface. A CAM system turns them into cutter location data, or it cuts the offset surface of the part by the planes and gets the tool centers directly.
The spacing on the surface follows from the gradient of along the surface. If is the unit normal, this gradient has length , so two passes whose planes are apart lie about
apart on the surface. On a flat floor () this is . On the plane it is exactly . On a wall that faces the direction () it is unbounded: such a wall lies in one plane or between two planes.
On a bilinear patch , the coordinate is bilinear. The code requires on the patch. Then each plane meets the patch in one curve , and the range of comes from two linear inequalities.
The algorithm
ISO-PLANAR(S, g, ε)- 1
for k ← 0, 1, ... while c_k = xmin + g/2 + k g < xmax do - 2
[u_lo, u_hi] ← the u for which the plane x = c_k meets the patch at 0 ≤ v ≤ 1 - 3
if there is no such u then go to the next plane - 4
the cut curve is u ↦ S(u, v(u)) with v(u) = (c_k - A - B u)/(C + D u) - 5
REFINE(u_lo, u_hi): if the curve point at the middle is farther than ε from the chord, refine both halves, else keep the chord - 6
append the pass, forward for even k and backward for odd k - 7
return the passes
Line L5 is a recursive midpoint test with a depth limit. It is a heuristic: it checks one point of the curve per chord, not all of them. On a general surface, line L4 is replaced by a surface-plane intersection, which marches along the curve with Newton steps or follows it across the patches of a model.
Example
Take the plane over , , as the bilinear patch with corners , , and , and take .
| step | plane | pass | length |
|---|---|---|---|
| L1 to L6 | 4 | ||
| L1 to L6 | 4 | ||
| ... | ... | ... | |
| L1 to L6 | 4 |
Each cut curve is straight, so line L5 keeps one chord. Neighbouring passes are apart on the surface, not 1. With slope they would be apart. A floor at next to the ramp gets passes 1 apart from the same planes, so a single gives two different finishes.
Correctness
Theorem. If on the patch, each plane meets it in one connected curve over the -interval of line L2, every returned point lies exactly on its plane and on the patch, and the refinement stops with at most chords per pass, each of which passes the midpoint test unless the depth limit was hit.
For fixed , grows linearly in , so each plane value is reached at exactly one , and the condition is a pair of linear inequalities in . The points are rational, so they are exact. The full proof is in the proof file.
What is measured. The chord error between midpoints is not bounded by the test. The spacing formula is a first-order estimate. The tests measure the spacing on curved random patches within 10 percent of for , and they measure every inner sample point within about half the local spacing of a pass. Near a patch boundary that runs almost parallel to the planes, the passes end at a grazing angle and some boundary points are farther from the passes.
Proof: On a bilinear patch with x growing in v, each drive plane cuts one exact curve, and the refinement stops with every chord passing its midpoint testfull
Setting. is a bilinear patch on with rational corners. Its first coordinate is , and the code requires and . The drive planes are with , where and are the smallest and largest of a corner. is the chord tolerance and the depth limit.
Claim. (a) for all , and for each the set is the graph of over the interval of line L2, or empty when line L2 finds no interval. (b) Every point the code returns lies exactly on the plane and on the patch. (c) The refinement of line L5 stops, returns at most chords, and every chord whose recursion did not hit the depth limit passes the midpoint test. (d) The loop of line L1 stops after at most planes.
Proof of (a). is affine in , positive at and at , so it is positive on . For a fixed , is affine in with positive slope , so has exactly one solution . That point is on the patch when . Multiplying by the positive denominator, this is and , two affine inequalities in . The set of that satisfy two affine inequalities is an interval (possibly empty), and line L2 computes it by intersecting with the half-line of each inequality: for it is when , when , and all or nothing when . So is the graph of over this interval, which is a single connected curve.
Proof of (b). Each returned point is with in the interval of (a), so it is on the patch, and by the choice of . The values are rationals, so both facts hold exactly.
Proof of (c). Each call either appends one end and returns, or makes two calls with the depth one smaller. A call at depth 0 never recurses, so the recursion tree has height at most and at most leaves, and each leaf appends one chord end. The chords are the parameter intervals of the leaves, which partition in order. A leaf reached with depth above 0 did not recurse, so its curve midpoint is within of its chord.
Proof of (d). Each pass of the loop adds to , and the loop stops when .
What is not proved. The midpoint test does not bound the distance from every point of the curve to its chord, so the chord error is measured in the tests, not proved. The spacing of the passes on the surface is a first-order estimate: the gradient of along the surface has length , where is the unit normal, so two level curves of that differ by lie about apart on the surface. For the plane this is exact: the passes and are parallel lines at distance , and . On a curved patch the tests measure the estimate within 10 percent for .
Complexity
There are planes. Each refinement makes at most splits, each with a constant number of rational operations, so the time is in the worst case. In practice the number of chords on a pass is about , where is the length of the pass and the radius of curvature of the curve, because a chord with sagitta on a circle of radius has length about . The extra space is the recursion depth .
Properties
- Across patches. The passes depend only on the planes and the geometry, not on the patches, so they run across the boundaries of a model of many patches.
- Even when seen from above. The passes project to equally spaced lines in the plane of the machine table.
- Spacing grows on steep slopes. On the surface the spacing is about , so the passes spread on slopes that are steep along and leave larger scallops there.
- Steady along slopes in . A slope that climbs along , parallel to the planes, keeps the spacing , because there.
Variants and improvements
- Cutter location surface. Cutting the offset of the part surface by the planes gives the tool centers directly, and a ball end mill on these centers does not gouge the part. On a grid this is the idea of the inverse tool offset.
- Two directions. A second pass set with planes machines the slopes that the first set treats badly. Some systems choose the direction per region from the normals.
- Adaptive plane spacing. Choosing each next plane from the scallop height of the last pass gives an iso-scallop toolpath.
- Z-level paths. Horizontal planes give the waterline passes of steep walls, the other half of the steep and shallow split. The same operation on a mesh is triangle mesh slicing.
When to use it
Use iso-planar passes for parts of many patches, and for shallow parts where stays small. On parts with steep walls, combine them with waterline passes for the steep areas, or use an iso-scallop path.
Pitfalls
- Walls that face the planes. A wall with normal along gets one pass or none. The code rejects a patch with for this reason.
- Grazing boundaries. A patch boundary that runs almost parallel to the planes is crossed at a grazing angle, and the material along it can be far from every pass. A last pass along the boundary fixes this.
- Midpoint test only. A curve can bend away from a chord and come back at the middle. A tighter test checks more points or bounds the curvature.
- Contact points, not centers. Offsetting the contact points along the normal can make the tool centers leave the planes and can gouge concave regions. Cutting the offset surface avoids both.
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.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/iso-planar-toolpath/. The authors are listed in prov/4X99MA.jsonl.
"""Iso-planar toolpath on a bilinear patch, with exact arithmetic.
The drive planes are x = c_k = xmin + g/2 + k g. On the bilinear patch
S(u, v), the coordinate x is A + B u + C v + D u v. The code needs
x_v = C + D u > 0 for 0 <= u <= 1, so that each plane meets the patch in one
curve v(u) = (c - A - B u) / (C + D u). This is a rational function, so every
point of the cut curve has rational coordinates and lies exactly on the plane
and on the patch.
Each curve is cut into chords by a recursive midpoint test: a chord is kept
when the curve point at the middle parameter is within eps of the chord.
This test is a heuristic. It does not bound the deviation at every point of
the curve, although on these smooth curves it does so in practice.
"""
from fractions import Fraction
Point = tuple[Fraction, Fraction, Fraction]
def _pt(p) -> Point:
if len(p) != 3:
raise ValueError("a corner needs 3 coordinates")
return tuple(Fraction(c) for c in p)
def sub(a, b):
return tuple(x - y for x, y in zip(a, b))
def dot(a, b):
return sum(x * y for x, y in zip(a, b))
def lerp(a, b, t):
return tuple(x + t * (y - x) for x, y in zip(a, b))
def dist2_segment(p, a, b) -> Fraction:
d = sub(b, a)
dd = dot(d, d)
t = 0 if dd == 0 else min(Fraction(1), max(Fraction(0), dot(sub(p, a), d) / dd))
q = tuple(x + t * y - z for x, y, z in zip(a, d, p))
return dot(q, q)
class BilinearPatch:
def __init__(self, p00, p10, p01, p11):
self.p00, self.p10, self.p01, self.p11 = map(_pt, (p00, p10, p01, p11))
x00, x10, x01, x11 = self.p00[0], self.p10[0], self.p01[0], self.p11[0]
self.A, self.B, self.C = x00, x10 - x00, x01 - x00
self.D = x00 - x10 - x01 + x11
if self.C <= 0 or self.C + self.D <= 0:
raise ValueError("x must grow with v on the whole patch")
def at(self, u, v) -> Point:
return lerp(lerp(self.p00, self.p10, u), lerp(self.p01, self.p11, u), v)
def v_on_plane(self, c, u) -> Fraction:
return (c - self.A - self.B * u) / (self.C + self.D * u)
def u_range(self, c):
"""The u for which the plane x = c meets the patch at 0 <= v <= 1, or None."""
lo, hi = Fraction(0), Fraction(1)
# v >= 0: (c - A) - B u >= 0; v <= 1: (C - c + A) + (D + B) u >= 0
for a, b in ((-self.B, c - self.A), (self.D + self.B, self.C - c + self.A)):
if a == 0:
if b < 0:
return None
elif a > 0:
lo = max(lo, -b / a)
else:
hi = min(hi, -b / a)
return (lo, hi) if lo <= hi else None
def x_range(self):
xs = [p[0] for p in (self.p00, self.p10, self.p01, self.p11)]
return min(xs), max(xs)
def _refine(curve, u0, u1, eps2, depth, out):
"""Append the chord ends for the curve between u0 and u1, without the start point."""
um = (u0 + u1) / 2
if depth > 0 and dist2_segment(curve(um), curve(u0), curve(u1)) > eps2:
_refine(curve, u0, um, eps2, depth - 1, out)
_refine(curve, um, u1, eps2, depth - 1, out)
else:
out.append(u1)
def iso_planar(patch: BilinearPatch, g, eps, max_depth=30):
"""The passes of an iso-planar path, as (c, [(u, point), ...]) from the lowest plane up.
Even passes run in the direction of growing u, odd passes the other way.
"""
g, eps = Fraction(g), Fraction(eps)
if g <= 0 or eps <= 0:
raise ValueError("g and eps must be positive")
xmin, xmax = patch.x_range()
passes = []
k = 0
c = xmin + g / 2
while c < xmax: # @line L1
rng = patch.u_range(c) # @line L2
if rng is None: # @line L3
k, c = k + 1, c + g
continue
def curve(u, c=c): # @line L4
return patch.at(u, patch.v_on_plane(c, u))
lo, hi = rng
us = [lo]
if hi > lo:
_refine(curve, lo, hi, eps * eps, max_depth, us) # @line L5
pts = [(u, curve(u)) for u in us]
passes.append((c, pts if k % 2 == 0 else pts[::-1])) # @line L6
k, c = k + 1, c + g
return passes # @line L7
test_iso_planar_toolpath.py 128 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/iso-planar-toolpath/. The authors are listed in prov/4X99MA.jsonl.
import math
import random
from fractions import Fraction as F
import pytest
from iso_planar_toolpath import BilinearPatch, dist2_segment, dot, iso_planar, sub
def ramp(m):
"""The plane z = m x over 0 <= x <= 10, 0 <= y <= 4, with x = 10 v."""
return BilinearPatch((0, 0, 0), (0, 4, 0), (10, 0, 10 * m), (10, 4, 10 * m))
def random_patch(rng):
j = lambda: F(rng.randrange(-8, 9), 4)
x10 = j()
p00 = (0, 0, F(rng.randrange(-20, 21), 4))
p10 = (x10, 10 + j(), F(rng.randrange(-20, 21), 4))
p01 = (10 + j(), j(), F(rng.randrange(-20, 21), 4))
p11 = (x10 + 10 + j(), 10 + j(), F(rng.randrange(-20, 21), 4))
return BilinearPatch(p00, p10, p01, p11)
def normal_x(patch, u, v):
p00, p10, p01, p11 = patch.p00, patch.p10, patch.p01, patch.p11
su = [float((1 - v) * (b - a) + v * (d - c)) for a, b, c, d in zip(p00, p10, p01, p11)]
sv = [float((1 - u) * (c - a) + u * (d - b)) for a, b, c, d in zip(p00, p10, p01, p11)]
n = (su[1] * sv[2] - su[2] * sv[1], su[2] * sv[0] - su[0] * sv[2], su[0] * sv[1] - su[1] * sv[0])
return n[0] / math.sqrt(n[0] ** 2 + n[1] ** 2 + n[2] ** 2)
def fdist(p, pts):
best = math.inf
for a, b in zip(pts, pts[1:]):
a, b = [float(x) for x in a], [float(x) for x in b]
d = [y - x for x, y in zip(a, b)]
dd = sum(x * x for x in d)
t = 0.0 if dd == 0 else min(1.0, max(0.0, sum((float(pi) - ai) * di for pi, ai, di in zip(p, a, d)) / dd))
best = min(best, math.dist([ai + t * di for ai, di in zip(a, d)], [float(x) for x in p]))
return best
def test_ramp_example():
passes = iso_planar(ramp(F(3, 4)), 1, F(1, 100))
assert [c for c, _ in passes] == [F(2 * k + 1, 2) for k in range(10)]
assert passes[0][1] == [(0, (F(1, 2), 0, F(3, 8))), (1, (F(1, 2), 4, F(3, 8)))]
assert passes[1][1][0][1] == (F(3, 2), 4, F(9, 8))
for (_, a), (_, b) in zip(passes, passes[1:]):
d = sub(a[0][1], b[-1][1])
assert dot(d, d) == F(25, 16) # the spacing on the surface is 5/4 for g = 1
def test_points_are_on_the_plane_and_on_the_patch():
rng = random.Random(1)
for _ in range(25):
patch = random_patch(rng)
for c, pts in iso_planar(patch, F(rng.randrange(1, 9), 4), F(1, 50)):
for u, p in pts:
v = patch.v_on_plane(c, u)
assert p[0] == c and 0 <= u <= 1 and 0 <= v <= 1
assert p == patch.at(u, v)
def test_every_chord_passes_the_midpoint_test():
rng = random.Random(2)
for _ in range(25):
patch = random_patch(rng)
eps = F(1, rng.randrange(10, 200))
for c, pts in iso_planar(patch, F(rng.randrange(1, 9), 4), eps):
for (u0, a), (u1, b) in zip(pts, pts[1:]):
um = (u0 + u1) / 2
assert dist2_segment(patch.at(um, patch.v_on_plane(c, um)), a, b) <= eps * eps
def test_spacing_on_the_surface_matches_the_slope_estimate():
"""Measured, not proved: the gap on the surface is about g / sqrt(1 - n_x^2)."""
rng = random.Random(3)
g = F(1, 4)
checked = 0
for _ in range(6):
patch = random_patch(rng)
passes = iso_planar(patch, g, F(1, 1000))
for (c, a), (_, b) in zip(passes[2:-3], passes[3:-2]):
u, p = a[len(a) // 2]
if not (F(1, 5) < u < F(4, 5)):
continue
v = patch.v_on_plane(c, u)
est = float(g) / math.sqrt(1 - normal_x(patch, u, v) ** 2)
got = fdist(p, [q for _, q in b])
assert abs(got - est) <= 0.1 * est
checked += 1
assert checked > 50
def test_coverage_measured():
"""Measured, not proved: an inner sample point is within about half the local gap of a pass.
Near a patch boundary that runs almost parallel to the planes, the passes
end at a grazing angle and the distance can be larger, so the samples
stay away from the boundary.
"""
rng = random.Random(4)
for _ in range(4):
patch = random_patch(rng)
g, eps = F(1, 2), F(1, 200)
passes = iso_planar(patch, g, eps)
polys = [[q for _, q in pts] for _, pts in passes]
for _ in range(60):
u, v = F(rng.randrange(10, 91), 100), F(rng.randrange(10, 91), 100)
est = float(g) / math.sqrt(1 - normal_x(patch, u, v) ** 2)
d = min(fdist(patch.at(u, v), poly) for poly in polys)
assert d <= 0.55 * est + float(eps)
def test_a_wall_facing_the_planes_is_rejected():
with pytest.raises(ValueError):
BilinearPatch((5, 0, 0), (5, 4, 0), (5, 0, 3), (5, 4, 3))
def test_bad_input():
with pytest.raises(ValueError):
iso_planar(ramp(1), 0, 1)
with pytest.raises(ValueError):
iso_planar(ramp(1), 1, 0)
History
The drive surface of APT part programs, a plane that the tool follows while it touches the part surface, is the older form of the method. Huang and Oliver (1994) studied tool paths from the cuts of sculptured surfaces by parallel planes as an alternative to constant-parameter paths, and Choi and Jerard (1998) present iso-planar machining next to the iso-parametric and iso-scallop methods.
References
- Byoung K. Choi and Robert B. Jerard, Sculptured Surface Machining, Theory and Applications, Kluwer Academic Publishers, 1998, chapter 6, introduction to tool-path generation methods, the part on Cartesian (iso-planar) machining
- Yunching Huang and James H. Oliver, Non-constant parameter NC tool path generation on sculptured surfaces, International Journal of Advanced Manufacturing Technology 9(5), 281-290, 1994, the tool paths from the cuts of the surface by parallel planes, and the choice of the plane spacing
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.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag 4X99MA Edit this page History Report an error Markdown