Algorithmadvanced
Iso-scallop toolpath
Also called constant scallop toolpath.
Places each pass so the scallop height to the last pass is constant, as in Suresh and Yang, which shortens the path for a given finish.
- Solves
- Toolpath planning
- Time
- O(N B G) worst
- Space
- O(1) extra
- Where
- B = bisection and doubling steps per pass; G = golden-section steps per height; N = number of passes
- Model
- Real RAM
- Properties
- deterministicnot exactiterative
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Krishnan Suresh, Daniel C. H. Yang, 1994
An iso-scallop toolpath finishes a surface with a ball end mill by placing each pass next to the last one so that the ridge left between them, the scallop height, is exactly the allowed value . Where the surface is concave across the passes, the ridges are lower for a given step, so the passes spread out; where it is convex, they move closer. Compared with a path that uses one fixed step chosen for the worst place, this gives the same finish with fewer passes. 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 places the passes on a profile surface , where the scallop between two passes is a two-dimensional problem, and it checks the result against the closed form for a cylinder.
In plain words
A round tool leaves a small ridge between two neighbouring passes. The finish is as good as the highest ridge, so a careful planner looks at the worst place on the part and uses the step that keeps the ridge small enough there. On the rest of the part this step is smaller than needed, and the tool runs more passes than it has to.
An iso-scallop path does not use one step. After each pass, it asks how far it can move the tool before the ridge gets too high, and it moves exactly that far. On a hollow, the tool can move farther. On a bump, it must move less.
The answer to that question is found by trial: try a step, measure the ridge, and halve the gap between a step that is too small and a step that is too large until the two agree.
The problem
The input is a surface, a ball end mill of radius and a target scallop height . The output is a set of passes whose neighbouring pairs leave a scallop of height , with the boundary as the first and the last pass.
On a translational surface the passes run along , and the cross-section is a profile with unit normal . The ball that touches the profile at has its center at , which is the cutter location of the pass. Between two passes the tool leaves a ridge whose top, the cusp, is the meeting point of the two tool circles on the side of the surface. The scallop height is the distance from the cusp to the profile.
For small steps the step along the surface that gives height is about
where is the radius of curvature of the surface across the passes, positive on a convex part and negative on a concave part, and on a plane gives . This is the formula of the scallop height page.
The algorithm
ISO-SCALLOP(profile on [a, b], r, h)- 1
t ← a; passes ← [a] - 2
while SCALLOP(t, b) > h do - 3
double a trial step from t until SCALLOP(t, t + step) > h, or the step reaches b - 4
bisect between the last good step and the first bad one, 60 times; t' ← the good end - 5
append t' to passes; t ← t' - 6
append b and return passes SCALLOP(t0, t1)- 7
c0 ← p(t0) + r n(t0); c1 ← p(t1) + r n(t1) - 8
q ← the meeting point of the circles of radius r around c0 and c1 on the side of the surface - 9
return the distance from q to the profile between t0 and t1, by golden-section search
Line L4 keeps the end whose height is at most , so every pair of passes stays within the target even if the height does not grow with the step. Line L9 is a golden-section search, and line L4 is the bisection method. On a general surface the same step is taken at many points along the last pass, and the new contact points are joined into the next pass.
Example
Take a ball end mill with and the target . The table gives the step between passes on three surfaces, measured along the surface.
| surface | step from the closed form | small-step formula |
|---|---|---|
| plane | ||
| convex cylinder, | ||
| concave cylinder, |
A path with one fixed step for a part that has all three regions must use 1.2602 everywhere, which is about 29 percent more passes on the concave region than an iso-scallop path. On the sine profile for , with and , the code places 62 passes, with steps in from 0.446 to 0.713. A fixed step of 0.446 in needs 69 passes. These counts are measured, not proved.
Correctness
Theorem. If ISO-SCALLOP returns , every neighbouring pair has a computed scallop height of at most . For each pair before the last, a pass at most farther would have a height above . If short steps always have a height at most , the method stops.
The doubling and the bisection keep two facts: the lower end has height at most , and the upper end has height above . The new pass is the lower end, and the gap between the ends is at most after 60 steps. On a convex or concave cylinder the cusp lies on the bisecting line by symmetry, and the law of cosines gives the closed-form angle with . The full proof is in the proof file.
What is measured. The theorem is about the computed height. The tests compare the passes on planes and on convex and concave cylinders with the closed forms, within . They compare the cusp distance on a sine profile with a brute force that shoots the normal ray from each sample point of the profile to the first of the two tool circles, within of . The pass counts against a fixed step are measured.
Proof: Every pair of neighbouring passes has a computed scallop height of at most the target, each step is maximal up to the bisection width, and the method stopsfull
Setting. The profile is on with continuously differentiable, unit normal , tool radius and target . The tool circle of the pass at has center . Write for the value that SCALLOP returns for the passes ; it is when the circles do not meet. The proof is about as computed. How well matches the true height of the ridge is a question of the golden-section search, which the tests measure.
Claim. (a) If ISO-SCALLOP returns , then for . (b) For , there is a with and , so no pass much farther than keeps the computed height at most in the same bracket. (c) If there is a with whenever , the method stops after at most passes. (d) Line L8 returns a point at distance from both centers.
Proof of (d). Let with and the midpoint. The point , with the unit vector perpendicular to and , has distance from both centers, for . The sign is chosen so the point lies on the side of the line that faces away from , the side of the surface.
Proof of (a) and (b). Line L2 runs the body only when for the current pass . Line L3 starts with and . While it sets and doubles the step. This keeps the invariant for , and it stops at the latest when , because . So after line L3, , , and either or . Each bisection step of line L4 replaces or by the midpoint and keeps both facts, and halves , so after 60 steps . The code then checks , so , and becomes the next pass, with . The last pair is added by line L6 only when . The passes grow strictly, because each new one is .
Proof of (c). Under the assumption, every trial point with has , so at the end of line L3 and during line L4, . At the end, . So each pass is more than past the last one, and the passes before number at most . The loop of line L3 doubles a positive step until it reaches , so it stops; line L4 runs 60 times.
The cylinder. On a convex cylinder of radius , the tool centers lie on the circle of radius around the axis. For two contacts at angles from a line through the axis, the cusp lies on that line by symmetry, at distance from the axis. It is from both centers, so the law of cosines gives , which is the closed form of the code. On a concave cylinder with , the centers lie on the circle of radius and the cusp at distance , with the same equation. The tests compare the passes with these angles.
What is assumed. Part (c) needs the computed height to be at most for short steps. For a smooth profile without gouging, the height of a short step is about times a factor that depends on the curvature, so the assumption holds, but this proof does not bound for a general profile. The method also does not prove that grows with ; parts (a) and (b) do not need it.
Complexity
Each call of SCALLOP takes golden-section steps. Each pass takes doubling steps and 60 bisection steps, with the first trial. With the number of these steps per pass, the time is for passes, and the space is apart from the output. On a general surface each pass is a curve, and the cost per pass grows with the number of points on it.
Properties
- Constant finish. Every pair of passes leaves the same scallop height, so no part of the surface is finished better than needed.
- Fewer passes. The path is shorter than an iso-parametric or iso-planar path for the same worst scallop. The saving depends on how much the curvature varies.
- Pass after pass. Each pass depends on the last one, so errors add up along the passes, and the passes cannot be computed in parallel.
- Not exact. The method finds roots and minima numerically; it does not use exact arithmetic.
Variants and improvements
- Curvature formula in place of the search. Lin and Koren (1996) compute the step from the target height and the local curvature, with the small-step formula, which is fast but only first order.
- Points along the pass. On a free-form surface, the next pass is made of the new contact points found at many points of the last one. Where the passes converge or diverge, points must be added or removed, and loops in the new pass must be cut off.
- Other tools. For a flat or bull-nose end mill the scallop depends on the tool axis, and the same placement works with the tool profile in place of the circle.
- Spirals. Iso-scallop passes can be joined into a spiral, as in the Fermat spiral paths of additive manufacturing.
When to use it
Use an iso-scallop path for the finishing of free-form surfaces whose curvature varies, where a fixed step would waste many passes, and where the finish must be even. For a roughing pass, or for a surface of almost constant curvature, a simpler iso-planar or iso-parametric path is enough.
Pitfalls
- Self-intersecting passes. On a free-form surface the next pass can fold over itself where the last pass is strongly curved. The loops must be detected and cut.
- Gouging. A ball whose radius exceeds the radius of a concave region cannot touch it without cutting the part, and the contact model fails. See gouge detection.
- Height not monotone. The scallop height need not grow with the step on a wavy surface. A search that assumes it does can skip a high ridge; the bisection here keeps a good end, but it can return a step that is not the largest good one.
- Error build-up. Each pass is placed from the last one, so a small error in the first pass carries to all later passes.
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-scallop-toolpath/. The authors are listed in prov/MQ38PN.jsonl.
"""Iso-scallop toolpath for a ball end mill on a translational surface.
The surface is z = f(x), the same for every y, and the passes run along y.
So the problem lives in the xz plane: the profile is p(t) = (t, f(t)), its
upward unit normal is n(t), and a ball of radius r that touches the profile at
p(t) has its center at c(t) = p(t) + r n(t). Between two passes the tool
leaves a ridge whose top, the cusp, is the meeting point of the two tool
circles on the side of the surface. The scallop height is the distance from
the cusp to the profile.
Each next pass is placed so that the scallop height to the last pass is the
target h: a bracket is found by doubling a trial step, and then 60 bisection
steps close it. The bisection always keeps the side with height at most h,
so every pair of neighbouring passes has a computed scallop height of at
most h.
This module uses floats. The answer is a numeric root, not a sign, and the
tests compare it with closed forms and a brute force within a tolerance.
"""
import math
GOLDEN = (math.sqrt(5) - 1) / 2
class Profile:
"""A profile z = f(x) on [a, b] with its derivative df."""
def __init__(self, f, df, a, b):
if not a < b:
raise ValueError("the domain must have a < b")
self.f, self.df, self.a, self.b = f, df, a, b
def point(self, t):
return (t, self.f(t))
def normal(self, t):
d = self.df(t)
k = math.hypot(d, 1.0)
return (-d / k, 1.0 / k)
def center(self, t, r):
(x, z), (nx, nz) = self.point(t), self.normal(t)
return (x + r * nx, z + r * nz)
def cusp(profile, r, t0, t1):
"""The meeting point of the two tool circles on the side of the surface, or None."""
c0, c1 = profile.center(t0, r), profile.center(t1, r) # @line L7
dx, dy = c1[0] - c0[0], c1[1] - c0[1]
d = math.hypot(dx, dy)
if d >= 2 * r:
return None # the circles do not meet: a strip between the passes is not cut
if d == 0:
return profile.point(t0)
m = ((c0[0] + c1[0]) / 2, (c0[1] + c1[1]) / 2)
k = math.sqrt(r * r - d * d / 4)
px, py = -dy / d, dx / d
n0, n1 = profile.normal(t0), profile.normal(t1)
down = (-(n0[0] + n1[0]), -(n0[1] + n1[1]))
s = 1.0 if px * down[0] + py * down[1] >= 0 else -1.0
return (m[0] + s * k * px, m[1] + s * k * py) # @line L8
def scallop(profile, r, t0, t1, iters=80):
"""The distance from the cusp between the passes t0 < t1 to the profile on [t0, t1]."""
q = cusp(profile, r, t0, t1)
if q is None:
return math.inf
def g(x):
p = profile.point(x)
return (p[0] - q[0]) ** 2 + (p[1] - q[1]) ** 2
lo, hi = t0, t1 # golden-section search for the nearest profile point
x1, x2 = hi - GOLDEN * (hi - lo), lo + GOLDEN * (hi - lo)
g1, g2 = g(x1), g(x2)
for _ in range(iters):
if g1 <= g2:
hi, x2, g2 = x2, x1, g1
x1 = hi - GOLDEN * (hi - lo)
g1 = g(x1)
else:
lo, x1, g1 = x1, x2, g2
x2 = lo + GOLDEN * (hi - lo)
g2 = g(x2)
return math.sqrt(min(g1, g2, g(t0), g(t1))) # @line L9
def next_pass(profile, r, h, t):
"""The next contact t' > t with scallop height h to the pass at t; requires scallop(t, b) > h."""
b = profile.b
step = math.sqrt(8 * r * h) / 2
lo, hi = t, min(t + step, b)
while scallop(profile, r, t, hi) <= h: # @line L3
lo, step = hi, 2 * step
hi = min(t + step, b)
for _ in range(60): # @line L4
mid = (lo + hi) / 2
if scallop(profile, r, t, mid) <= h:
lo = mid
else:
hi = mid
if lo <= t:
raise ValueError("the target height is too small to advance")
return lo
def iso_scallop(profile, r, h):
"""The contact parameters of the passes, from a to b."""
if r <= 0 or h <= 0:
raise ValueError("r and h must be positive")
t = profile.a # @line L1
passes = [t]
while scallop(profile, r, t, profile.b) > h: # @line L2
t = next_pass(profile, r, h, t)
passes.append(t) # @line L5
passes.append(profile.b) # @line L6
return passes
def cylinder_step(R, r, h, convex=True):
"""The closed-form angle between neighbouring contacts on a cylinder of radius R."""
big, rho = (R + r, R + h) if convex else (R - r, R - h)
return 2 * math.acos((big * big + rho * rho - r * r) / (2 * big * rho))
test_iso_scallop_toolpath.py 128 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/iso-scallop-toolpath/. The authors are listed in prov/MQ38PN.jsonl.
import math
import random
import pytest
from iso_scallop_toolpath import Profile, cylinder_step, iso_scallop, scallop
def convex_cylinder(R, a, b):
return Profile(lambda x: math.sqrt(R * R - x * x), lambda x: -x / math.sqrt(R * R - x * x), a, b)
def concave_cylinder(R, a, b):
return Profile(lambda x: -math.sqrt(R * R - x * x), lambda x: x / math.sqrt(R * R - x * x), a, b)
def sine(A, L, b):
return Profile(lambda x: A * math.sin(x / L), lambda x: A / L * math.cos(x / L), 0.0, b)
def parabola(k, a, b):
return Profile(lambda x: k * x * x, lambda x: 2 * k * x, a, b)
def ray_thickness(profile, r, t0, t1, samples=800):
"""Brute force: shoot the normal ray from each sample point of the profile between the
passes, and measure how far it goes before it enters one of the two tool disks.
The largest such length is the height of the ridge of material left between them.
The search runs on a grid, then on a finer grid around the best sample, three times."""
centers = [profile.center(t, r) for t in (t0, t1)]
def thickness(x):
p, n = profile.point(x), profile.normal(x)
hit = math.inf
for c in centers:
w = (p[0] - c[0], p[1] - c[1])
bb = n[0] * w[0] + n[1] * w[1]
cc = w[0] * w[0] + w[1] * w[1] - r * r
disc = bb * bb - cc
if disc >= 0:
hit = min(hit, max(-bb - math.sqrt(disc), 0.0))
return hit
lo, hi = t0, t1
for _ in range(3):
xs = [lo + (hi - lo) * i / samples for i in range(samples + 1)]
k = max(range(len(xs)), key=lambda i: thickness(xs[i]))
lo, hi = xs[max(k - 1, 0)], xs[min(k + 1, samples)]
return max(thickness(x) for x in xs)
def test_plane_matches_the_closed_form():
for r, h in ((5.0, 0.01), (5.0, 0.417424), (3.0, 0.2)):
passes = iso_scallop(Profile(lambda x: 0.0, lambda x: 0.0, 0.0, 20.0), r, h)
w = 2 * math.sqrt(r * r - (r - h) ** 2)
for t0, t1 in zip(passes[:-2], passes[1:-1]):
assert abs((t1 - t0) - w) < 1e-9
assert abs(2 * math.sqrt(25 - (5 - 0.417424) ** 2) - 4) < 1e-5
def test_cylinders_match_the_closed_form():
R, r = 20.0, 5.0
for h in (0.01, 0.05, 0.3):
for convex, prof in ((True, convex_cylinder(R, 0.0, 14.0)), (False, concave_cylinder(R, 0.0, 14.0))):
passes = iso_scallop(prof, r, h)
theta = cylinder_step(R, r, h, convex)
angles = [math.asin(t / R) for t in passes]
for a0, a1 in zip(angles[:-2], angles[1:-1]):
assert abs((a1 - a0) - theta) < 1e-9
assert angles[-1] - angles[-2] <= theta + 1e-9
def test_cylinder_closed_form_values():
R, r = 20.0, 5.0
# inverse of the forward values for theta = 0.1: convex 0.127393, concave 0.075269
assert abs(cylinder_step(R, r, 0.127393, True) - 0.1) < 1e-5
assert abs(cylinder_step(R, r, 0.075269, False) - 0.1) < 1e-5
def test_every_pair_has_the_target_height():
rng = random.Random(5)
profiles = [sine(3.0, 4.0, 30.0), parabola(0.05, -10.0, 10.0), sine(1.0, 2.5, 20.0)]
for prof in profiles:
r = rng.choice([1.0, 2.0])
h = rng.choice([0.01, 0.02, 0.05])
passes = iso_scallop(prof, r, h)
assert passes[0] == prof.a and passes[-1] == prof.b
assert all(t0 < t1 for t0, t1 in zip(passes, passes[1:]))
for t0, t1 in zip(passes[:-2], passes[1:-1]):
assert abs(scallop(prof, r, t0, t1) - h) < 1e-9
assert scallop(prof, r, passes[-2], passes[-1]) <= h + 1e-12
def test_scallop_matches_the_ray_brute_force():
"""Measured: the cusp distance and the largest ray thickness agree to 1e-4 of h or better."""
rng = random.Random(7)
prof = sine(3.0, 4.0, 30.0)
for _ in range(12):
r = rng.choice([1.0, 2.0, 2.5])
t0 = rng.uniform(0.0, 26.0)
t1 = t0 + rng.uniform(0.3, 1.5)
h = scallop(prof, r, t0, t1)
brute = ray_thickness(prof, r, t0, t1)
assert abs(h - brute) <= 1e-4 * h + 1e-7, (t0, t1, h, brute)
for convex, prof2 in ((True, convex_cylinder(20.0, -10.0, 10.0)), (False, concave_cylinder(20.0, -10.0, 10.0))):
t1 = 20.0 * math.sin(0.2)
h = scallop(prof2, 5.0, 0.0, t1)
assert abs(h - ray_thickness(prof2, 5.0, 0.0, t1)) < 1e-6
assert abs(h - (0.542575 if convex else 0.304456)) < 1e-6
def test_fewer_passes_than_a_constant_worst_case_step():
"""Measured: a constant step equal to the smallest iso-scallop step needs more passes."""
for prof, r, h in ((sine(3.0, 4.0, 30.0), 2.0, 0.02), (parabola(0.05, -10.0, 10.0), 1.0, 0.01)):
passes = iso_scallop(prof, r, h)
smallest = min(t1 - t0 for t0, t1 in zip(passes[:-2], passes[1:-1]))
constant = math.ceil((prof.b - prof.a) / smallest) + 1
assert len(passes) < constant
def test_bad_input():
with pytest.raises(ValueError):
iso_scallop(sine(1.0, 1.0, 5.0), 0.0, 0.1)
with pytest.raises(ValueError):
Profile(lambda x: 0.0, lambda x: 0.0, 1.0, 1.0)
History
Suresh and Yang (1994) placed each pass on a free-form surface so that the scallop height to the last pass is constant. Lin and Koren (1996) made the method efficient with a curvature-based step and a direct construction of the next pass. Choi and Jerard (1998) compare iso-scallop machining with the iso-parametric and iso-planar 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 constant scallop (iso-scallop) machining
- Krishnan Suresh and Daniel C. H. Yang, Constant scallop-height machining of free-form surfaces, ASME Journal of Engineering for Industry 116(2), 253-259, 1994, the placement of each pass from the last one so that the scallop height between them is constant
- Rong-Shine Lin and Yoram Koren, Efficient tool-path planning for machining free-form surfaces, ASME Journal of Engineering for Industry 118(1), 20-28, 1996, the path interval from the target scallop height and the local curvature, and the generation of the next pass from the last one
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 MQ38PN Edit this page History Report an error Markdown