3-axis CAM from STL (height maps, drop-cutter finishing, gouge checks)
cnccamstltoolpathsdrop-cutterheight-mapverification
How cncfileoptimizer.com turns an STL into gouge-free 3-axis toolpaths in the browser: Z-level roughing from a conservative height map, exact drop-cutter finishing, and an independent verifier. The safety rules were each proven necessary by a failing test or benchmark.
Height map (conservative by construction)
- Each grid cell stores an upper bound of the surface height in that cell.
- The tool-center offset map must be valid for the tool axis anywhere in the cell, so the tool kernel is padded by a full cell diagonal. A half-diagonal pad was proven non-conservative on a mower-wheel model: 3% of positions were under-bounded by up to 48 mm.
Roughing (Z-level)
- At each level, raster every 4-connected pocket completely, nearest pocket first; straight or L-shaped in-pocket links; a wall pass only along real walls; ramped entries.
- Links between areas climb to
max(offset surface, remaining stock) + clearance, computed from a cleared-material map dilated by the tool radius. - Approach: rapid only down to the disc-max of the remaining stock within the tool radius, then feed vertically to the stock, then ramp. A rapid can never touch a higher terrace beside the entry.
Finishing (parallel) with an exact drop-cutter
- Rows at the exact stepover. Along each row, the tool-center height Z* is computed exactly against the triangles (vertex, edge and facet contacts for flat, ball, bull-nose and V-bit tools), with a bucket grid and z-max pruning. Sampling is adaptive (midpoint plus kink detection).
- Lift by tol/2 and simplify with a one-sided Douglas-Peucker (undercut tolerance tol/4), so the path lies in [Z*, Z* + tol]: never below the surface.
- Measured on an analytic hemisphere (3 mm ball, tol 0.01 mm): the path stays within 0.01 mm above the true surface at every slope, versus 0.4 to 0.9 mm with the grid method.
- Waterline and steep/shallow finishing still use the grid (walls about 1.5 x cell); the fix is to push contour points to exact wall contact by bisection with the drop-cutter.
- Bull-nose and V-bit edge contacts use a golden-section search (28 iterations); a closed form would be faster.
Independent verification
- Rapids and roughing are checked over every touched cell; parallel finishing by dense sampling against the drop-cutter with a radial allowance equal to the path tolerance (walls are vertical jumps in Z*). Vertical moves are judged at their end point; XY excursions under 1e-4 mm are ignored.
- The verifier shares no geometry code with the planner. Tests use a brute-force mesh check and a stock simulation.
- Known gap: rapids are verified against the model surface, not the remaining stock; link safety rests on the linker (covered by a stock simulation test).
Benchmark (mower wheel, 200 x 200 x 52.5 mm, 26,910 triangles, 0.2 mm grid)
Roughing 61k moves, 192 m cutting, 75 m rapid (was 566 m before link fixes); finishing 151k moves; about 324 min machine time; about 30 s to plan and verify in Node (verification is roughly half).
STL parsing gotchas
Handle both binary and ASCII STL, and binary files whose triangle count in the header lies. Orientation tools: pick the up axis, scale, zero the top, set the XY origin, rotate about Z.
See also
- Optimizing CNC G-code safely (arc fitting, simplification, self-checks)
- 2.5-D CNC design-to-G-code (distance-field offsetting, independent verification)
- Generating watertight print meshes in code (three.js, earcut, manifold)