Implementation of the straight skeleton algorithm as described by Felkel and Obdržálek in their 1998 conference paper Straight skeleton implementation.
Project description
shapely-polyskel
[!NOTE] This package is a fork of an implementation written by Ármin Scipiades (Botffy). The original code can be found under the link.
This is a Python 3 implementation of the straight skeleton algorithm as described by Felkel and Obdržálek in their 1998 conference paper Straight skeleton implementation.
The algorithm itself is fairly dated, and shown to be incorrect for certain input polygons. This implementation is a bit crap, and does not really attempt to fix the algorithm. It works kinda okay for most real-life input (for example country contours or floor plans).
For a modern and excellent overview of the topic please refer to Stefan Huber's excellent Computing Straight Skeleton and Motorcycle Graphs: Theory and Practice.
Installation
shapely-polyskel is available on PyPI:
pip install shapely-polyskel
Usage
Basic example (skeletonize
)
from shapely_polyskel import skeletonize
rectangle = [(40, 40), (40, 310), (520, 310), (520, 40)]
skeleton = skeletonize(polygon=rectangle)
Polygon with holes (skeletonize
)
from shapely_polyskel import skeletonize
rectangle = [(40, 40), (40, 310), (520, 310), (520, 40)]
holes = [[(100, 100), (200, 100), (200, 150), (100, 150)]]
skeleton = skeletonize(polygon=rectangle, holes=holes)
Basic example (StraightSkeleton
)
from shapely import Polygon
from shapely_polyskel import StraightSkeleton
# In the case of using 'StraightSkeleton', the direction of the polygon/hole
# points is not important.
polygon = Polygon(
[(520, 40), (520, 310), (40, 310), (40, 40)],
[[(100, 150), (200, 150), (200, 100), (100, 100)]],
)
straight_skeleton = StraightSkeleton(polygon=polygon)
# Returns the same list as 'skeletonize'
skeleton = straight_skeleton.straight_skeleton
source_points = straight_skeleton.source_points(points3d=False)
ridges = straight_skeleton.ridges()
sinks = straight_skeleton.sinks()
More examples can be found in the notebooks folder.
Forks & ports
- Yongha Hwang's fork. Check out it to see polyskel in sweet real-life action :heart: :heart: :heart:.
- Polyskel-Swift a Swift port.
- bpolyskel is a port for Blender, making some sweet roofs :heart:.
Project details
Release history Release notifications | RSS feed
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
File details
Details for the file shapely_polyskel-0.1.1.tar.gz
.
File metadata
- Download URL: shapely_polyskel-0.1.1.tar.gz
- Upload date:
- Size: 17.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff3143c0e594683500e4c15f787a8596f8ae2dbcd6fba8c1a53d88ab1bc4c76c |
|
MD5 | c5aede10057d548bad59ba9a4be550b7 |
|
BLAKE2b-256 | 4a2b6162aacdd82894358d46be3b8497c4ccd6e12fa14a7be2df66c75f9c06c3 |
File details
Details for the file shapely_polyskel-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: shapely_polyskel-0.1.1-py3-none-any.whl
- Upload date:
- Size: 14.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77bf106d7eb442cd0e2bdbc4efab5fd4a4a9b5d54c29615c75f62fd8f2037b70 |
|
MD5 | 018155290907be9d201ef09006d0b484 |
|
BLAKE2b-256 | be6648c586341405f1d3c147b54d0b514fa0f40666e8185c36dce29ae9628dec |