offset a polyline or polygon in 2D space
Project description
offset_poly
Move a polyline or polygon (left) by a given offset.
A counterclockwise polygon will be offset to the inside. I clockwise polygon will be offset to the outside.
offset_polygon
def offset_polygon(polyline: Sequence[_Vec2], offset: float) -> list[_Vec2]:
"""Offset polygon edges (to the left) by a constant amount.
:param polyline: polyline
:param offset: distance to offset from each edge
:return: polygon offset by offset
"""
offset_polyline
def offset_polyline(polyline: Sequence[_Vec2], offset: float) -> list[_Vec2]:
"""Offset polygon edges (to the left) by a constant amount.
:param polyline: polyline
:param offset: distance to offset from each edge
:return: polyline offset by offset
"""
The difference between the two is that offset_polygon
will close the polygon if it is not already closed, whereas offset_polyline
will leave the polyline open even if the first and last points are identical.
This package is the simplest version of polyline offsetting, it does not anticipate or account for self intersections that may come up when offsetting a polyline.
This is not nearly as sophisticated as curve offsetting, but you can use this for control polygon offsetting, which will be nearly as good in some instances.
- multiple points (knots in your control points) are preserved.
- if input[0] == input[-1], output[0] will equal output[-1]
You may see (nan, nan) in the result.
If you pass two adjacent, opposite, parallel edges, you will get a (nan, nan) in the result. With points A -> B -> A, for instance, there is no point that would be any given distance (except 0) left of both A B and B A.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for offset_poly-0.3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1afc752ee24f8b015a3b25466213ddbb6ef573efe047786d15ffc8fd1674c354 |
|
MD5 | 8d1ebff7dcaa4b78ddc3b6511e765571 |
|
BLAKE2b-256 | 8dbcc92b89f3dcb504b49e59318a2755d130e6054f9b9b32a024b6a38c32b5a6 |