Algorithmcore
Iso-parametric toolpath
Also called isoparametric machining.
Machines a parametric surface along curves of constant u or v, simple to compute but uneven in spacing where the parameterization is distorted.
- Solves
- Toolpath planning
- Time
- O(N) worst
- Space
- O(1) extra
- Where
- N = number of passes
- Model
- Real RAM
- Properties
- deterministicexactiterative
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Gary C. Loney, Tulga M. Ozsoy, 1987
An iso-parametric toolpath machines a parametric surface by moving the tool along the curves where one parameter is constant, , back and forth. The curves come directly from the surface equation, so the path is easy to compute and lies on the surface exactly. The cost is uneven spacing: equal steps in give equal steps on the surface only where the parameterization is even, and elsewhere the passes crowd together or spread apart. 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 builds the path on a bilinear patch, where every iso-curve is straight and the largest gap between passes has an exact formula.
In plain words
A surface in a CAD model is made like a sheet of graph paper that has been stretched and bent. The grid lines of the paper are still there on the bent sheet. An iso-parametric path just traces these grid lines, one after the other, back and forth.
This is simple, because the grid lines are known. The problem is that the sheet was stretched more in some places than in others. Where it was stretched a lot, the grid lines are far apart, and the tool leaves ridges. Where it was squeezed, the lines are close, and the tool cuts the same place many times.
To be safe, the gap must be small enough at the widest place. Then the path is denser than needed everywhere else.
The problem
The input is a surface patch and a path interval , the largest allowed distance between neighbouring passes. For a ball end mill of radius on a nearly flat surface, the interval that gives a scallop height is about . The output is a cutter contact path on the surface, which a CAM system turns into cutter location data by offsetting along the surface normal.
The gap between the passes and at the parameter is about , where is the partial derivative. The length is the stretch of the parameterization across the passes, and it comes from the first fundamental form. The passes are , with chosen so that the largest gap is at most .
On a bilinear patch , the surface is linear in for fixed , so the gap is exactly with . Every iso-curve of a bilinear patch is a straight line, which makes it a doubly ruled surface.
The algorithm
ISO-PARAMETRIC(S, w)- 1
M ← max(|S_v(0)|², |S_v(1)|²) ▷ the largest squared gap factor is at an end - 2
N ← the smallest positive integer with M ≤ N² w² - 3
for j ← 0 to N do - 4
C_j ← the curve u ↦ S(u, j/N), forward for even j and backward for odd j - 5
append C_j, joined to the previous pass along the boundary curve u = 0 or u = 1 - 6
return the path
Line L1 uses the fact that is a convex quadratic in on a bilinear patch, so its largest value is at or . Line L2 compares rationals, so is exact. For a tensor-product B-spline or NURBS surface, line L1 bounds over the patch, and line L4 also steps along each curve with a chord tolerance, since the curves are not straight.
Example
Take the flat trapezoid with , , and , and . Then and , so and .
| step | pass | from | to | gap to the next pass at and |
|---|---|---|---|---|
| L4, L5 | and | |||
| L4, L5 | and | |||
| L4, L5 | and | |||
| L4, L5 | and | |||
| L4, L5 |
The passes fan out: they are apart at the long side and apart at the short side. The path has length about , with on the passes and on the links. Any path that keeps every point of this region within has length at least , because a path of length widened by covers at most of area, and the trapezoid has area 10.
Correctness
Theorem. On a bilinear patch, is the smallest number of passes with all gaps at most , the path lies on the patch, and every point of the patch is within of the path.
For fixed the patch is linear in , so the points with form a straight segment on the patch of length between two passes. The function is the squared norm of an affine map of , so it is convex and largest at an end, and line L2 makes every such segment at most long. A point on a segment of length at most is within of one of its ends. The full proof is in the proof file.
The bound is about the distance between passes. The scallop height that a tool leaves also depends on the tool and the curvature, see scallop height.
Proof: On a bilinear patch, the iso-parametric passes chosen from the end gaps keep every surface point within half the path interval of the pathfull
Setting. on , with corners in , and is rational. Let , and . Let be the value of line L2 and . Pass is the segment from to , and is the union of the passes and the links.
Claim. (a) Line L2 stops, and is the smallest positive integer with for all . (b) Pass is the iso-parametric curve , and the links lie on the patch. (c) Every point of the patch lies within distance of , along a straight segment that lies on the patch.
Step 1 (the patch is linear in each parameter). Expanding the formula gives with , and in the same way with and . So for fixed , is the affine map from to , and for fixed , is affine with derivative . This proves the first part of (b). The link from pass to pass joins to for , and by the same fact it is the curve on , which lies on the patch.
Step 2 (the largest gap is at an end). The function is the square of the norm of an affine map, so it is convex: for , , and the convexity of gives . With and , , the value of line L1.
Step 3 (proof of (a)). The test of line L2 is , and grows without bound as grows, so the loop stops at the smallest with . By Step 2, holds if and only if . So is the smallest positive integer with that property.
Step 4 (proof of (c)). Let and choose with . By Step 1 the points for form a straight segment on the patch from to , of length by (a). The point lies on this segment, so it is within of or of , along the segment. By (b), lies on pass and lies on pass .
Remark. The bound of (c) holds for every , but the gap is only where is largest. Where is small, the passes are closer than needed, which is the unevenness of iso-parametric paths. On a curved surface the gap between two iso-curves is only to first order, and this proof does not apply.
Complexity
Line L2 counts up to , and lines L3 to L5 write points, so the time is with . Integer square roots would give in time polynomial in the bit size, but the count is cheap next to the path. The extra space is apart from the output. On a curved patch, each pass also costs one point per forward step, and the number of steps grows with the curvature and shrinks with the chord tolerance.
Properties
- Exact passes. The passes are curves of the surface model, with no intersection to solve and no projection.
- Patch by patch. Each patch of a model gets its own passes. The passes of neighbouring patches do not line up, and the boundaries between patches need extra care.
- Uneven spacing. The gap varies with , so the path is longer than needed wherever is below its largest value.
- Conservative. With set by the largest gap, no gap exceeds .
Variants and improvements
- Adaptive iso-curves. Elber and Cohen (1994) add passes only where two neighbouring passes are too far apart, so the spacing becomes more even.
- Iso-planar paths. Cutting the surface with parallel planes gives passes that run across patch boundaries. See iso-planar toolpath.
- Iso-scallop paths. Placing each pass from the last one so that the scallop height is constant removes the waste of uneven passes. See iso-scallop toolpath.
- Reparameterization. An arc-length parametrization of the boundary curves makes the passes more even at the boundaries, but not in general inside the patch.
When to use it
Use an iso-parametric path for a single patch whose parameterization is close to even, such as a gently bent sheet, and for finishing along the flow of a surface. Avoid it on trimmed patches, on patches that are very distorted, and on models with many small patches, where an iso-planar or iso-scallop path is shorter and more even.
Pitfalls
- Trimmed surfaces. A trimmed patch keeps only part of its parameter square. The iso-curves must be clipped to the trim curves in the parameter plane, or the tool cuts outside the face.
- Degenerate patches. At a pole, where a whole boundary of the parameter square maps to one point, all passes meet, and the tool cuts the same point many times.
- First-order gap only. On a curved surface, is only an estimate of the gap. The true gap can be larger where changes fast.
- Contact path, not tool path. The iso-curves give cutter contact points. The tool center is offset from them, and on concave parts with small radius the offset can gouge the 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.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/iso-parametric-toolpath/. The authors are listed in prov/SQ9VDF.jsonl.
"""Iso-parametric toolpath on a bilinear patch, with exact arithmetic.
The patch is S(u, v) = (1-u)(1-v) P00 + u(1-v) P10 + (1-u) v P01 + u v P11
for 0 <= u, v <= 1. The passes are the iso-v curves v = j / N. On a bilinear
patch every iso-parametric curve is a straight segment, so each pass is
exact and needs no forward step.
For a fixed u the patch is linear in v, with S_v(u) = (1-u)(P01 - P00) +
u(P11 - P10). The gap between the passes v_j and v_j+1 at u is therefore
exactly |S_v(u)| / N. Its square is a convex quadratic in u, so the gap is
largest at u = 0 or u = 1, and N is the smallest integer with
max(|S_v(0)|, |S_v(1)|) <= N w.
The path is a list of contact points on the surface (the CC path). The
cutter location points come from it by an offset along the surface normal.
"""
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))
class BilinearPatch:
def __init__(self, p00, p10, p01, p11):
self.p00, self.p10, self.p01, self.p11 = map(_pt, (p00, p10, p01, p11))
def at(self, u, v) -> Point:
u, v = Fraction(u), Fraction(v)
return lerp(lerp(self.p00, self.p10, u), lerp(self.p01, self.p11, u), v)
def s_v(self, u) -> Point:
"""The derivative in v, which does not depend on v."""
return lerp(sub(self.p01, self.p00), sub(self.p11, self.p10), Fraction(u))
def pass_count(patch: BilinearPatch, w) -> int:
"""The smallest N such that the gap between neighbouring iso-v passes is at most w."""
w = Fraction(w)
if w <= 0:
raise ValueError("the path interval must be positive")
m = max(dot(patch.s_v(0), patch.s_v(0)), dot(patch.s_v(1), patch.s_v(1))) # @line L1
n = 1
while m > n * n * w * w: # @line L2
n += 1
return n
def iso_parametric(patch: BilinearPatch, w) -> list[Point]:
"""The zigzag CC path: passes v = j / N, linked along the boundary curves u = 0 and u = 1."""
n = pass_count(patch, w)
path = []
for j in range(n + 1): # @line L3
v = Fraction(j, n)
a, b = patch.at(0, v), patch.at(1, v)
# The pass is the straight segment from a to b, run back and forth.
seg = [a, b] if j % 2 == 0 else [b, a] # @line L4
# Moving from the last point of one pass to the first point of the next
# runs along the boundary curve u = 0 or u = 1, which is straight too.
path.extend(seg) # @line L5
return path # @line L6
def path_segments(path):
return list(zip(path, path[1:]))
test_iso_parametric_toolpath.py 100 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/iso-parametric-toolpath/. The authors are listed in prov/SQ9VDF.jsonl.
import math
import random
from fractions import Fraction as F
import pytest
from iso_parametric_toolpath import BilinearPatch, dot, iso_parametric, pass_count, path_segments, sub
TRAPEZOID = BilinearPatch((0, 0, 0), (4, 0, 0), (0, 1, 0), (4, 4, 0))
def dist2(p, a, b):
"""Exact squared distance from p to the segment ab in space."""
d = sub(b, a)
dd = dot(d, d)
t = 0 if dd == 0 else min(F(1), max(F(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)
def random_patch(rng):
return BilinearPatch(*[tuple(rng.randrange(-10, 11) for _ in range(3)) for _ in range(4)])
def test_trapezoid_example():
assert pass_count(TRAPEZOID, 1) == 4
path = iso_parametric(TRAPEZOID, 1)
assert path[:4] == [(0, 0, 0), (4, 0, 0), (4, 1, 0), (0, F(1, 4), 0)]
assert len(path) == 10 and path[-2:] == [(0, 1, 0), (4, 4, 0)]
gap0 = TRAPEZOID.at(0, F(1, 4))[1] - TRAPEZOID.at(0, 0)[1]
gap1 = TRAPEZOID.at(1, F(1, 4))[1] - TRAPEZOID.at(1, 0)[1]
assert (gap0, gap1) == (F(1, 4), 1)
length = sum(math.dist(a, b) for a, b in path_segments(path))
assert abs(length - 24.43) < 0.01
def test_gap_formula_and_its_maximum():
rng = random.Random(1)
for _ in range(40):
patch = random_patch(rng)
w = F(rng.randrange(1, 13), 2)
n = pass_count(patch, w)
ends = max(dot(patch.s_v(0), patch.s_v(0)), dot(patch.s_v(1), patch.s_v(1)))
for _ in range(10):
u = F(rng.randrange(0, 101), 100)
j = rng.randrange(0, n)
g = sub(patch.at(u, F(j + 1, n)), patch.at(u, F(j, n)))
sv = patch.s_v(u)
assert dot(g, g) * n * n == dot(sv, sv)
assert dot(sv, sv) <= ends
assert dot(g, g) <= w * w
def test_pass_count_is_minimal():
rng = random.Random(2)
for _ in range(60):
patch = random_patch(rng)
w = F(rng.randrange(1, 13), 2)
n = pass_count(patch, w)
if n > 1:
worst = max(dot(g, g) for g in (sub(patch.at(u, F(1, n - 1)), patch.at(u, 0)) for u in (0, 1)))
assert worst > w * w
def test_every_surface_point_is_near_the_path():
"""Brute force: the exact distance from sample points of the patch to the path is at most w/2."""
rng = random.Random(3)
for _ in range(25):
patch = random_patch(rng)
w = F(rng.randrange(2, 13), 2)
segs = path_segments(iso_parametric(patch, w))
samples = [(F(i, 6), F(j, 6)) for i in range(7) for j in range(7)]
samples += [(F(rng.randrange(0, 1001), 1000), F(rng.randrange(0, 1001), 1000)) for _ in range(30)]
for u, v in samples:
p = patch.at(u, v)
assert min(dist2(p, a, b) for a, b in segs) <= w * w / 4
def test_path_lies_on_the_patch():
rng = random.Random(4)
for _ in range(20):
patch = random_patch(rng)
path = iso_parametric(patch, F(rng.randrange(1, 9)))
n = len(path) // 2 - 1
for (a, b), j in zip(zip(path[::2], path[1::2]), range(n + 1)):
v = F(j, n)
for t in (F(0), F(1, 3), F(1)):
q = tuple(x + t * (y - x) for x, y in zip(a, b))
u = t if j % 2 == 0 else 1 - t
assert q == patch.at(u, v)
def test_bad_input():
with pytest.raises(ValueError):
pass_count(TRAPEZOID, 0)
with pytest.raises(ValueError):
BilinearPatch((0, 0), (1, 0, 0), (0, 1, 0), (1, 1, 0))
History
Iso-parametric paths were the first tool paths for sculptured surfaces, because they come straight from the surface equations of Bezier and B-spline patches. Loney and Ozsoy (1987) described iso-parametric machining of free-form patches. Elber and Cohen (1994) made the passes adaptive, and Choi and Jerard (1998) compare it with the iso-planar and iso-scallop methods in their book.
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 iso-parametric machining
- Gary C. Loney and Tulga M. Ozsoy, NC machining of free form surfaces, Computer-Aided Design 19(2), 85-90, 1987, the tool paths along the iso-parametric curves of a surface patch, and the choice of the step between them
- Gershon Elber and Elaine Cohen, Toolpath generation for freeform surface models, Computer-Aided Design 26(6), 490-496, 1994, adaptive iso-curves, which add iso-parametric passes only where the gap between the passes is too large
Where this leads
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 SQ9VDF Edit this page History Report an error Markdown