Skip to content

pygeo.offset_polygon

fabian-flassig edited this page Jun 8, 2026 · 4 revisions

Computes the parallel offset of a 2D polygon and returns both the offset polygon and the mantle faces between the original and the offset boundary.

This function is located in the pygeo module.

The mantle faces are the strips of material that lie between the original polygon boundary and the offset boundary, with their ends mitered along the angle bisectors of the original corners. They are useful for constructing frames, ribbed structures or any other geometry that requires the connecting material between an inset and its source.

Internally pygeo.offset_polygon is implemented on top of PYTHA's median-axis-based parallel-offset algorithm, so it handles short edges, self-intersection collapse and similar degeneracies cleanly without the spike artefacts that a naive per-vertex bisector offset would produce.

offset_loops, mantle_faces = pygeo.offset_polygon(points, distance)
Parameter Type Description
points {{u,v}, ...} Coordinates of the input polygon as a single closed loop in 2D. The loop must contain at least 3 points and is treated as implicitly closed.
distance number Offset distance. Positive values move the contour outward, negative values move it inward.

Return values

Type Description
offset_loops {{loop_points_1} [, {loop_points_2}, ...]}
mantle_faces {{loop_points_1, original_segment_index=integer} [, ...]}

Notes:

  • The function performs a purely 2D operation in the local u/v plane and does not create any elements in the project.
  • The orientation of points is preserved. For a counter-clockwise input, the offset loops are also counter-clockwise.
  • Mantle faces are returned as closed quadrilateral loops oriented counter-clockwise. Their corners follow the original edge from points[i] to points[i+1], then transition along the bisector to the offset boundary, then back along the offset edge to the bisector at points[i].
  • For arc segments in the input boundary, use pygeo.offset_polygon_ex. The non-_ex variant treats consecutive points as straight line segments.

Example:

local points = {
    {0,   0},
    {100, 0},
    {100, 50},
    {0,   50},
}

local offset_loops, mantle_faces = pygeo.offset_polygon(points, -10)

-- offset_loops[1][1] is the inset rectangle, inset by 10 units.
-- mantle_faces[1] through mantle_faces[4] are the four trapezoid strips
-- between the original rectangle and the offset rectangle, mitered at
-- the corners.
for i, face in ipairs(mantle_faces) do
    local face_points = face[1]
    local edge_index  = face.original_segment_index
    -- face_points is the loop, edge_index identifies the source edge.
end

Version Support:

Minimum PYTHA Version: V27

See also:

pygeo, pygeo.offset_polygon_ex, pygeo.offset_polyline, pygeo.clean_polygon_2d, pytha.create_polygon_ex

Clone this wiki locally