Algorithmadvanced
Inverse tool offset
Also called ITO method.
Computes cutter locations on a grid that do not gouge the sampled part, as the highest inverted tool placed at each sample, after Kishinami, Kondo and Saito.
- Solves
- Toolpath planning
- Time
- O(n k) worst
- Space
- O(n) extra
- Where
- k = number of grid points in the tool footprint; n = number of grid points
- Model
- Real RAM
- Properties
- deterministicexactiterative
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Takeshi Kishinami, Tsukasa Kondo, Katsumasa Saito, 1988
The inverse tool offset (ITO) method computes the cutter location of a tool that moves straight down onto a part, at every point of a grid. It does not ask where the tool touches the part. Instead it turns the tool upside down, puts this inverted tool at every sample point of the part, and keeps the highest of all these shapes at each grid point. The upper envelope is the surface on which the tool tip can move without cutting into any sample, which is the cutter location surface of three-axis machining. The method works the same for every part, however many patches, holes or steep walls it has, because it only needs heights. 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 computes the envelope on a height grid by scattering, as a z-buffer does, and it checks it against a direct maximum over all samples.
In plain words
Press a ball down onto a bumpy surface until it rests on the bumps. The height of the lowest point of the ball is where the tool tip may go. Doing this at every grid point one by one is slow, because at each point the ball has to be compared with all the bumps under it.
Turn the question around. Each bump pushes the ball up when the ball is near. If you hang an upside-down ball under each bump, the height that a bump forces on the tip at a nearby point is the height of that hanging ball there. So hang one upside-down ball under every bump and take, at each point, the highest one.
The result is a smooth surface over the part. The tool tip runs along it and never pushes into a bump.
The problem
The part is a height field sampled on a grid with spacing . The tool points down, and its shape is a function on a disk of offsets : the height of the tool surface above its tip at the horizontal offset . A ball end mill of radius has , and a flat end mill has on its disk. The tool tip at grid point must be at least as high as
where is the set of samples under the tool. This is the lowest tip height that leaves every sample at or under the tool surface. For a ball end mill on a smooth part, the tool center is at height , and the surface of centers is the offset surface of the part, cut at the points where the offset folds.
In terms of mathematical morphology, is the grayscale dilation of by the structuring function .
The algorithm
INVERSE-TOOL-OFFSET(f, T)- 1
Z[p] ← −∞ for every grid point p - 2
for each sample q of the part do - 3
for each offset o in the footprint of the tool do - 4
p ← q + o; skip p if it is off the grid - 5
Z[p] ← max(Z[p], f(q) − T(o)) ▷ the inverted tool at q, as in a z-buffer - 6
return Z
The value is the height of the inverted tool, hung at the sample , above the point . For a symmetric tool, , so this is the same as in the formula for . The inverted tool is computed once, as a small table of heights over the footprint.
Example
Take a grid with spacing , a flat floor at height 0, and one pin of height 1 at the middle sample. The tool is a ball end mill with . Its footprint has the 13 offsets with , and is 0 at the center, at distance 0.5, at distance 0.707 and 1 at distance 1.
| grid point on the middle row | |||||
|---|---|---|---|---|---|
| highest inverted tool | floor 0, pin | pin | pin | pin | floor 0, pin 0 |
| 0 | 0.8660 | 1 | 0.8660 | 0 |
The tip rides over the pin on a dome of radius 1, which is the inverted ball hung under the pin. At the diagonal neighbour , . Elsewhere the floor wins and .
Correctness
Theorem. INVERSE-TOOL-OFFSET returns, at each grid point , . With the tip at , the tool is at or above every sample under it and touches at least one, and every lower tip height leaves a sample above the tool.
The scatter loop sends the value to the point . For a fixed , the pairs that reach it are exactly the samples in its footprint, by the symmetry of the footprint, with the same values as in the formula, and the maximum does not depend on the order. The sample that attains the maximum touches the tool, and any lower tip cuts into it. The full proof is in the proof file.
The claim is about the samples only. The tests compare the scatter with a direct maximum over all samples for exact equality, with Fractions for the flat tool, and they check the ball on the tilted plane against the continuous answer . The grid value is never above it, and in the tests it is below it by at most 0.0056 for and , which is a measurement.
Proof: The scattered inverse tool gives the lowest tip height at each grid point that leaves every sample under the tool, with contact at one samplefull
Setting. The grid points are and gives the sampled heights of the part. The tool is a finite footprint with , symmetric ( implies ), and a height function with and . The tool with its tip at height above grid point has its surface at height above the grid point , for . For let , the samples under the tool. Let be the array that INVERSE-TOOL-OFFSET returns.
Claim. For every :
(a) ;
(b) with the tip at , the tool surface is at or above every sample in , and it touches at least one of them;
(c) is the lowest tip height with property (b): every lower tip height puts some sample of above the tool surface.
The loops stop after passes of line L5.
Termination. Lines L2 and L3 run over the finite sets and , so line L5 runs at most times.
Proof of (a). Line L5 at sample and offset with compares the value into . Fix . The pairs that reach are those with and , which by the symmetry of are exactly the , with . Their values are by the symmetry of . Line L1 starts empty, and line L5 keeps the largest value seen, so after the loops is the maximum of these values. The set holds itself, since , so the maximum is over a nonempty set.
Proof of (b). For , (a) gives , so : the tool surface above is at or above the sample. For a that attains the maximum, equality holds, so the tool touches .
Proof of (c). Let . Then , so the sample lies above the tool surface.
Remarks. (1) Claim (a) says that is the grayscale dilation of by the structuring function on , so INVERSE-TOOL-OFFSET is a morphological dilation of the height field. (2) The claims are about the samples. Between grid points the part can rise above the tool, for example a thin rib that lies between samples, so the method is gouge-free only at the samples. (3) Each value is computed by the same expression in the scatter loop and in a direct maximum, so with floats the two give equal results, and the tests compare them for equality.
Complexity
The footprint of a tool of radius has grid points. Lines L2 to L5 run times for samples, so the time is , and takes space. Halving the grid spacing multiplies by 4 and by 4, so the time grows by 16. Each step is a table lookup, a subtraction and a comparison, which suits graphics hardware: drawing the inverted tool at every sample with a depth test is a z-buffer rendering.
Properties
- Robust. The method needs only heights, so gaps, overlaps and bad patches of the model do not stop it.
- Gouge-free at the samples. No sample lies above the tool surface. Between samples the part can rise above the tool.
- Any tool shape. Ball, flat, bull-nose and tapered tools all work by their height table .
- Order-free. The maximum is the same in any order of the samples, so the loop can run in parallel.
- Three-axis only. The tool axis is fixed and vertical.
Variants and improvements
- Rendering on graphics hardware. Drawing the inverted tool as a mesh at every sample with a depth buffer computes at the speed of the graphics card.
- Gather form. At each grid point, take the maximum over the samples in the footprint. This gives the same values and suits a parallel machine.
- Paths from the surface. Tool paths are read from along grid rows, which gives iso-planar passes, or along level sets of , which gives waterline passes.
- Verification. The same grid is used to simulate the cut and check it, as in the z-map model and in NC verification.
When to use it
Use the inverse tool offset for three-axis machining of complex parts given as meshes or as many patches, such as dies and molds, where robustness matters more than exact geometry. Use an exact method on the surface model, with gouge detection, when the part has thin features or when a fine grid is too costly.
Pitfalls
- Features between samples. A rib thinner than the grid spacing can fall between samples and get cut. The grid spacing must be smaller than the smallest feature.
- Grid error. The grid value is below the continuous answer by an amount that grows with the spacing, so a finished surface can show small cuts below the true part. In the tests on a tilted plane the error was below for spacing 0.25. The error depends on the spacing and the slope, so choose the spacing from the tolerance of the part.
- Edges of the grid. Near the edge of the grid, the footprint holds fewer samples, and the tool can drop over the edge. Pad the grid with the stock height or with the part outside the machining area.
- Memory. A fine grid over a large part needs much memory, and the time grows with the fourth power of the inverse spacing.
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/inverse-tool-offset/. The authors are listed in prov/RAY63F.jsonl.
"""Inverse tool offset (ITO) on a height grid.
The part is a height field sampled on a square grid: f[i][j] is the height
of the part at (i d, j d), with grid spacing d. The tool points straight
down. Its shape is a function T(o) >= 0 for offsets o in its footprint: the
height of the tool surface above its tip at the horizontal offset o. A ball
end mill of radius r has T(o) = r - sqrt(r^2 - |o|^2), and a flat end mill
has T = 0 on its disk.
The cutter location of the tip at the grid point p is the lowest height at
which the tool touches no sample from above:
Z[p] = max over samples q in the footprint of p of f[q] - T(q - p).
The ITO method computes Z by scattering: it puts the tool upside down at each
sample q, so that its surface is the height f[q] - T(o) at p = q + o, and
keeps the highest value at each grid point, like a z-buffer. For a symmetric
tool, T(q - p) = T(p - q), so the scatter and the gather give the same Z.
Heights may be int, float or Fraction. With Fractions and a flat tool, every
step is exact.
"""
import math
def footprint(r, d):
"""The grid offsets (a, b) of the tool disk of radius r on a grid of spacing d."""
if r <= 0 or d <= 0:
raise ValueError("the radius and the spacing must be positive")
k = int(r // d)
return [(a, b) for a in range(-k, k + 1) for b in range(-k, k + 1) if (a * a + b * b) * d * d <= r * r]
def ball_tool(r, d):
"""The inverted ball end mill: offset -> height of the tool surface above the tip."""
return {(a, b): r - math.sqrt(r * r - (a * a + b * b) * d * d) for a, b in footprint(r, d)}
def flat_tool(r, d):
"""The flat end mill: height 0 on the whole disk."""
return {o: 0 for o in footprint(r, d)}
def inverse_tool_offset(f, tool):
"""Cutter location heights Z of the tool tip at every grid point, by scattering.
A grid point whose footprint holds no sample keeps the value None, which
cannot happen when the footprint holds the offset (0, 0).
"""
nx, ny = len(f), len(f[0])
z = [[None] * ny for _ in range(nx)] # @line L1
for i in range(nx): # @line L2
for j in range(ny):
h = f[i][j]
for (a, b), t in tool.items(): # @line L3
p, q = i + a, j + b # @line L4
if 0 <= p < nx and 0 <= q < ny:
v = h - t
if z[p][q] is None or v > z[p][q]: # @line L5
z[p][q] = v
return z # @line L6
test_inverse_tool_offset.py 104 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/inverse-tool-offset/. The authors are listed in prov/RAY63F.jsonl.
import math
import random
from fractions import Fraction as F
import pytest
from inverse_tool_offset import ball_tool, flat_tool, footprint, inverse_tool_offset
def gather(f, tool):
"""Brute force: at each grid point, the maximum over all samples of the part of
f[q] - T(q - p), taken only where q - p is in the footprint."""
nx, ny = len(f), len(f[0])
z = [[None] * ny for _ in range(nx)]
for p in range(nx):
for q in range(ny):
for i in range(nx):
for j in range(ny):
o = (i - p, j - q)
if o in tool:
v = f[i][j] - tool[o]
if z[p][q] is None or v > z[p][q]:
z[p][q] = v
return z
def terrain(rng, nx, ny):
return [[rng.uniform(-1.0, 1.0) for _ in range(ny)] for _ in range(nx)]
def test_pin_example():
f = [[0.0] * 5 for _ in range(5)]
f[2][2] = 1.0
z = inverse_tool_offset(f, ball_tool(1.0, 0.5))
row = [round(v, 6) for v in z[2]]
assert row == [0.0, 0.866025, 1.0, 0.866025, 0.0]
assert round(z[1][1], 6) == 0.707107
assert len(footprint(1.0, 0.5)) == 13
def test_scatter_equals_gather_exactly():
rng = random.Random(1)
for _ in range(4):
nx, ny = rng.randrange(8, 14), rng.randrange(8, 14)
f = terrain(rng, nx, ny)
tool = ball_tool(rng.choice([0.5, 1.0, 1.5]), 0.25)
assert inverse_tool_offset(f, tool) == gather(f, tool)
def test_flat_tool_is_exact_with_fractions():
rng = random.Random(2)
for _ in range(4):
nx, ny = rng.randrange(6, 11), rng.randrange(6, 11)
f = [[F(rng.randrange(-50, 51), 7) for _ in range(ny)] for _ in range(nx)]
tool = flat_tool(F(3, 2), F(1, 2))
z = inverse_tool_offset(f, tool)
assert z == gather(f, tool)
for p in range(nx):
for q in range(ny):
disk = [f[i][j] for i in range(nx) for j in range(ny) if (i - p) ** 2 + (j - q) ** 2 <= 9]
assert z[p][q] == max(disk)
def test_no_gouge_at_samples_and_contact():
rng = random.Random(3)
f = terrain(rng, 16, 16)
tool = ball_tool(1.0, 0.25)
z = inverse_tool_offset(f, tool)
for p in range(16):
for q in range(16):
touch = False
for (a, b), t in tool.items():
i, j = p + a, q + b
if 0 <= i < 16 and 0 <= j < 16:
assert z[p][q] + t >= f[i][j]
touch = touch or z[p][q] + t == f[i][j]
assert touch
def test_ball_on_a_tilted_plane():
"""The grid result is at most the continuous offset, and close to it (measured)."""
for m, d in ((0.5, 0.25), (1.0, 0.25), (2.0, 0.125)):
r = 2.0
n = int(12 / d)
f = [[m * i * d for _ in range(n)] for i in range(n)]
z = inverse_tool_offset(f, ball_tool(r, d))
k = int(r / d) + 1
worst = 0.0
for i in range(k, n - k):
exact = m * i * d + r * (math.sqrt(1 + m * m) - 1)
for j in range(k, n - k):
assert z[i][j] <= exact + 1e-12
worst = max(worst, exact - z[i][j])
assert worst <= m * d * d
def test_bad_input():
with pytest.raises(ValueError):
footprint(0, 1)
with pytest.raises(ValueError):
ball_tool(1.0, 0.0)
History
Kishinami, Kondo and Saito developed the inverse offset method in Japan in the late 1980s, and Kondo, Kishinami and Saito (1988) described a machining system based on it. The method spread with the z-map model and graphics hardware, and Choi and Jerard (1998) present it as a standard way to compute cutter location data for sculptured surfaces.
References
- Tsukasa Kondo, Takeshi Kishinami and Katsumasa Saito, Machining system based on inverse offset method, Journal of the Japan Society for Precision Engineering 54(5), 971-976, 1988, the inverse offset of the tool over the part and the cutter location surface built from it
- Byoung K. Choi and Robert B. Jerard, Sculptured Surface Machining, Theory and Applications, Kluwer Academic Publishers, 1998, the chapters on the computation of cutter location data for sculptured surfaces, where the inverse tool offset method is presented
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 RAY63F Edit this page History Report an error Markdown