Skip to content

compas_cnc.toolpath_2d_hatch.toolpath_2d_hatch ¤

toolpath_2d_hatch(boundary, spacing, angle=0.0, holes=None, radius=0.0, z=None, safe_z=None, contour=True, direction=None, depth=0.0, step=None)

Raster (zig-zag) fill of a closed polygon -- optionally with holes -- by parallel hatch lines at a user angle, connected into ONE continuous path, and optionally repeated DOWN a user depth in equal layers joined by a gentle helical ramp around the contour.

The cut region is boundary minus holes, compensated for the tool: the boundary is shrunk inward and every hole is grown outward by radius so the tool CENTRE path keeps a full radius clear of every wall instead of riding the edge. The compensated region is filled with hatch lines spacing apart at angle, then the lines are walked in BOUSTROPHEDON (snake) order: sorted across the hatch direction row by row, and each next line entered by its NEARER end so the tool reverses every row instead of jumping around at random.

A link between two successive lines that would drag the cutter through a hole is replaced by a RETRACT over the island (lift to safe_z, rapid across, plunge back), so no cutting move ever enters a hole.

Depth (layered roughing). With depth > 0 the fill is not a single flat pass but a stack of equal layers step deep, cut from z straight down to z - depth (the pass count is rounded up so the actual step is <= the request). Material is removed layer by layer. Between layers the tool does NOT lift and plunge: it follows the boundary contour ONCE around while descending the next step, a HELICAL ramp at the shallowest angle the perimeter allows (atan(step / perimeter)) -- the same loop that finishes the wall. So the path ramps gently into the stock, clears a layer, ramps down the wall into the next, and repeats until z - depth is reached. With depth == 0 (the default) it is the original single flat fill at z.

The path plunges/ramps once at the start, sweeps each layer, and traverses home at safe_z -- so it ends where it began.

Parameters:

  • boundary (:class:`compas.geometry.Polyline` | :class:`compas.geometry.Polygon` | sequence of points) –

    Closed outer boundary (XY plane; the fill is laid at z).

  • spacing (float) –

    Perpendicular distance between hatch lines -- the stepover. Must be > 0.

  • angle (float, default: 0.0 ) –

    Hatch direction in radians (CCW from +X). Defaults to 0.0 (horizontal).

  • holes (sequence, default: None ) –

    Closed rings the fill must avoid (islands). Defaults to None.

  • radius (float, default: 0.0 ) –

    Tool radius for cutter compensation: the boundary is inset and the holes are grown by this much before hatching. Defaults to 0.0 (the raw boundary/holes, tool centre rides the edge).

  • z (float, default: None ) –

    World-Z of the TOP fill plane. Defaults to the mean Z of boundary -- i.e. the toolpath lands on the geometry's own plane unless told otherwise. With depth set this is the top of the stock; cutting goes downward.

  • safe_z (float, default: None ) –

    Plunge/retract height. Clamped up to at least :data:MIN_CLEARANCE above z. Defaults to z + MIN_CLEARANCE.

  • contour (bool, default: True ) –

    After the raster fill, run a finishing pass once around each wall (the inset boundary and the grown holes) for a clean edge. Defaults to True. With depth it runs once at the FINAL (bottom) level.

  • direction ((None, climb, conventional), default: None ) –

    Milling direction for hard materials (assumes a CW / M3 tool; on M4 pick the opposite label). When set, the contour walls and the descent ramp are wound accordingly (boundary as a pocket, holes as islands) and the fill goes one-directional (every pass cut the same way, with a lift + rapid return between). None (default) doesn't care -- the faster mixed zig-zag, fine for soft materials.

  • depth (float, default: 0.0 ) –

    Total material depth to remove below z. 0 (default) is a single flat fill at z; > 0 clears in layers down to z - depth.

  • step (float, default: None ) –

    Maximum Z per layer when depth > 0. The depth is split into ceil(depth / step) EQUAL layers so the actual step is <= step. When omitted the whole depth is one layer. Ignored if depth == 0.

Attributes:

  • path (:class:`compas.geometry.Polyline`) –

    The full tool-centre path: plunge/ramp, snake fill per layer (with retracts over islands and helical descents between layers), retract, home. Starts and ends at the same safe-Z position.

  • fill (:class:`compas.geometry.Polyline`) –

    The working raster snake of the TOP cutting layer (without lead-in/out).

  • lines (list[:class:`compas.geometry.Line`]) –

    The raw clipped hatch segments (over the compensated region), before connection.

  • offset_boundary (list[:class:`compas.geometry.Polyline`]) –

    The boundary after inward tool-radius compensation (the actual fill edge).

  • offset_holes (list[:class:`compas.geometry.Polyline`]) –

    The holes after outward tool-radius compensation (the kept-out islands).

  • levels (list[float]) –

    The world-Z of every cutting layer, top to bottom (one entry when depth == 0).

  • layers (int) –

    Number of cutting layers (len(levels)).

  • step (float) –

    Actual vertical descent per layer (0 when depth == 0).

  • ramp_angle (float) –

    Angle of the helical inter-layer descent in radians (0 when there is no ramp).

  • radius, depth, safe_z (float) –