Skip to main content

raygeo.geo.algo.medial_axis

Medial axis of a rectangular pocket — skeleton from center to corners.

Medial axis of a rectangular pocket — skeleton from center to corners. Medial Axis Transform (MAT) computation.

The MAT is the skeleton of a 2D domain — the set of points equidistant to two or more boundary features. It is computed via Delaunay-get_circumcenter extraction from a constrained triangulation of the domain boundary.

  • MedialAxis.compute — compute the MAT of a domain (with optional holes).
  • MedialAxis.path_between — find a path between two points along the skeleton.
  • MedialAxis.trim_to_polygons — filter nodes to those inside given polygons.

MedialAxis

Medial Axis Transform of a planar domain.

The MAT is the set of points equidistant to two or more boundary features, forming the skeleton of the free space.

Usage:

axis = MedialAxis.compute(outer, holes)
path = axis.path_between((x1, y1), (x2, y2))
trimmed = axis.trim_to_polygons(polygons)
nodes = axis.nodes
clearances = axis.clearances
edges = axis.edges
root = axis.root
branches = axis.branches

branches

branches: list[list[int]]

clearances

clearances: list[float]

edges

edges: list[tuple[int, int]]

nodes

nodes: list[tuple[float, float]]

root

root: int

compute()

compute(
outer: Sequence[tuple[float, float]],
holes: Optional[Sequence[Sequence[tuple[float, float]]]] = None,
min_clearance: float = 1.0,
sampling_spacing: float = 1.0,
) -> MedialAxis

Compute the Medial Axis Transform of a planar domain.

ParameterTypeDescription
outerSequence[tuple[float, float]]Outer boundary polygon (list of (x, y) vertices).
holesOptional[Sequence[Sequence[tuple[float, float]]]] = NoneList of hole polygons (each a list of (x, y) vertices).
min_clearancefloat = 1.0Minimum clearance distance in mm.
sampling_spacingfloat = 1.0Spacing between sampling points in mm.
ReturnsMedialAxisMedialAxis object.

Medial axis with three rectangular islands — skeleton branches around each obstacle.

Medial axis with three rectangular islands — skeleton branches around each obstacle.

Medial axis of a Y-shaped channel — skeleton follows the branching topology.

Medial axis of a Y-shaped channel — skeleton follows the branching topology.

path_between()

path_between(
from_pt: tuple[float, float],
to_pt: tuple[float, float],
) -> Optional[list[tuple[float, float]]]

Find a path between two points along the medial axis skeleton.

ParameterTypeDescription
from_pttuple[float, float]Start point (x, y).
to_pttuple[float, float]End point (x, y).
ReturnsOptional[list[tuple[float, float]]]List of (x, y) waypoints along the medial axis.

MAT path routing: a path between two points along the medial axis skeleton, avoiding the island

MAT path routing: a path between two points along the medial axis skeleton, avoiding the island

trim_to_polygons()

trim_to_polygons(
polygons: Sequence[Sequence[tuple[float, float]]],
) -> MedialAxis

Return a new MedialAxis containing only nodes whose positions fall inside at least one of the given polygons.

ParameterTypeDescription
polygonsSequence[Sequence[tuple[float, float]]]List of polygons to trim against.
ReturnsMedialAxisTrimmed MedialAxis.

MAT trimmed to cleared area: original (gray) and trimmed nodes (blue) after multiple clearing passes

MAT trimmed to cleared area: original (gray) and trimmed nodes (blue) after multiple clearing passes