LoginSignup
1
0

More than 1 year has passed since last update.

straight skeleton (scikit-geometry 利用)

Last updated at Posted at 2021-10-28

こんにちは。
straight skeleton を描きました(下図内の赤線)。scikit-geometry を利用しています。

用途として、例えば河川の両岸形状を与え、その中心線を求めるなどです。

skeleton
$ 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()
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0