offset_polygon

compas.geometry.offset_polygon(polygon, distance, tol=None)[source]

Offset a polygon (closed) by a distance.

Parameters:
polygonsequence[point] | compas.geometry.Polygon

The XYZ coordinates of the corners of the polygon. The first and last coordinates must not be identical.

distancefloat | list[tuple[float, float]]

The offset distance as float. A single value determines a constant offset globally. A list of pairs of local offset values per line segment can be used to create variable offsets.

tolfloat, optional

A tolerance value for intersection calculations. Default is TOL.absolute.

Returns:
list[[float, float, float]]

The XYZ coordinates of the corners of the offset polygon. The first and last coordinates are identical.

Notes

The offset direction is determined by the normal of the polygon. If the polygon is in the XY plane and the normal is along the positive Z axis, positive offset distances will result in an offset towards the inside of the polygon.

The algorithm works also for spatial polygons that do not perfectly fit a plane.

Examples

>>> from compas.geometry import Polygon
>>> polygon = Polygon([(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0)])
>>> offsetted_polygon = offset_polygon(polygon, 0.5)
>>> offsetted_polygon
[[0.5, 0.5, 0.0], [0.5, 0.5, 0.0], [0.5, 0.5, 0.0], [0.5, 0.5, 0.0]]