こんにちは。
straight skeleton を描きました(下図内の赤線)。scikit-geometry を利用しています。
用途として、例えば河川の両岸形状を与え、その中心線を求めるなどです。
$ brew install cgal pybind11 python3
$ pip3 install matplotlib
$ pip3 install git+https://github.com/scikit-geometry/scikit-geometry.git
$ ./skeleton.py
skeleton.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import skgeom as sg
from skgeom.draw import draw
import matplotlib.pyplot as plt
def draw_skeleton(polygon, skeleton, show_time=False):
draw(polygon)
if skeleton:
for h in skeleton.halfedges:
if h.is_bisector:
p1 = h.vertex.point
p2 = h.opposite.vertex.point
plt.plot([p1.x(), p2.x()], [p1.y(), p2.y()], 'r-', lw=2)
if show_time:
for v in skeleton.vertices:
plt.gcf().gca().add_artist(plt.Circle(
(v.point.x(), v.point.y()),
v.time, color='blue', fill=False))
poly = sg.Polygon([(0, 0), (4, 2), (8, 1), (8, 3), (4, 5), (0, 2)])
skel = sg.skeleton.create_interior_straight_skeleton(poly)
draw_skeleton(poly, skel, show_time=True)
plt.show()
plt.close()