-
Notifications
You must be signed in to change notification settings - Fork 18
pygeo.offset_polygon
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. |
| Type | Description |
|---|---|
offset_loops |
{{loop_points_1} [, {loop_points_2}, ...]} |
mantle_faces |
{{loop_points_1, original_segment_index=integer} [, ...]} |
- The function performs a purely 2D operation in the local
u/vplane and does not create any elements in the project. - The orientation of
pointsis 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]topoints[i+1], then transition along the bisector to the offset boundary, then back along the offset edge to the bisector atpoints[i]. - For arc segments in the input boundary, use
pygeo.offset_polygon_ex. The non-_exvariant treats consecutive points as straight line segments.
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.
endMinimum PYTHA Version: V27
pygeo, pygeo.offset_polygon_ex, pygeo.offset_polyline, pygeo.clean_polygon_2d, pytha.create_polygon_ex