2D Straight Skeleton

../_images/cgal_straight_skeleton_2.png
from compas_cgal.straight_skeleton_2 import interior_straight_skeleton
from compas_viewer import Viewer

points = [
    (-1.91, 3.59, 0.0),
    (-5.53, -5.22, 0.0),
    (-0.39, -1.98, 0.0),
    (2.98, -5.51, 0.0),
    (4.83, -2.02, 0.0),
    (9.70, -3.63, 0.0),
    (12.23, 1.25, 0.0),
    (3.42, 0.66, 0.0),
    (2.92, 4.03, 0.0),
    (-1.91, 3.59, 0.0),
]


graph = interior_straight_skeleton(points)

# ==============================================================================
# Viz
# ==============================================================================

viewer = Viewer(width=1600, height=900)
for edge in graph.edges():
    line = graph.edge_line(edge)
    if graph.edge_attribute(edge, "inner_bisector"):
        print(edge, "inner_bisector")
        viewer.add(line, linecolor=(1.0, 0.0, 0.0), linewidth=2)
    elif graph.edge_attribute(edge, "bisector"):
        viewer.add(line, linecolor=(0.0, 0.0, 1.0))
    else:
        viewer.add(line, linecolor=(0.0, 0.0, 0.0))
viewer.show()
../_images/cgal_straight_skeleton_2_holes.png
from compas.geometry import Polygon
from compas_viewer import Viewer

from compas_cgal.straight_skeleton_2 import interior_straight_skeleton_with_holes

points = [
    (-1.91, 3.59, 0.0),
    (-5.53, -5.22, 0.0),
    (-0.39, -1.98, 0.0),
    (2.98, -5.51, 0.0),
    (4.83, -2.02, 0.0),
    (9.70, -3.63, 0.0),
    (12.23, 1.25, 0.0),
    (3.42, 0.66, 0.0),
    (2.92, 4.03, 0.0),
    (-1.91, 3.59, 0.0),
]

holes = [
    [(0.42, 0.88, 0.0), (1.1, -1.0, 0.0), (-1.97, -0.93, 0.0), (-1.25, 1.82, 0.0)],
    [(4.25, -0.64, 0.0), (2.9, -3.03, 0.0), (2.12, -2.16, 0.0), (2.89, -0.36, 0.0)],
    [(10.6, 0.29, 0.0), (9.48, -1.54, 0.0), (5.48, -1.26, 0.0), (5.98, -0.04, 0.0)],
]


polygon = Polygon(points)
holes = [Polygon(hole) for hole in holes]
graph = interior_straight_skeleton_with_holes(polygon, holes)

# ==============================================================================
# Viz
# ==============================================================================

viewer = Viewer(width=1600, height=900)

for edge in graph.edges():
    line = graph.edge_line(edge)
    if graph.edge_attribute(edge, "inner_bisector"):
        viewer.scene.add(line, linecolor=(1.0, 0.0, 0.0), linewidth=2)
    elif graph.edge_attribute(edge, "bisector"):
        viewer.scene.add(line, linecolor=(0.0, 0.0, 1.0))
    else:
        viewer.scene.add(line, linecolor=(0.0, 0.0, 0.0))
viewer.show()
../_images/cgal_straight_skeleton_2_offset.png
from compas.geometry import Polygon
from compas_viewer import Viewer

from compas_cgal.straight_skeleton_2 import offset_polygon

points = [
    (-1.91, 3.59, 0.0),
    (-5.53, -5.22, 0.0),
    (-0.39, -1.98, 0.0),
    (2.98, -5.51, 0.0),
    (4.83, -2.02, 0.0),
    (9.70, -3.63, 0.0),
    (12.23, 1.25, 0.0),
    (3.42, 0.66, 0.0),
    (2.92, 4.03, 0.0),
    (-1.91, 3.59, 0.0),
]
polygon = Polygon(points)
offset = 1.5

offset_polygon_inner = offset_polygon(points, offset)
offset_polygon_outer = offset_polygon(points, -offset)

# ==============================================================================
# Viz
# ==============================================================================

viewer = Viewer(width=1600, height=900)
viewer.scene.add(polygon)
viewer.config.renderer.show_grid = False

for opolygon in offset_polygon_inner:
    viewer.scene.add(opolygon, linecolor=(1.0, 0.0, 0.0), facecolor=(1.0, 1.0, 1.0, 0.0))
for opolygon in offset_polygon_outer:
    viewer.scene.add(opolygon, linecolor=(0.0, 0.0, 1.0), facecolor=(1.0, 1.0, 1.0, 0.0))

viewer.show()
../_images/cgal_straight_skeleton_2_offset_weighted.png
from compas.geometry import Polygon
from compas_viewer import Viewer

from compas_cgal.straight_skeleton_2 import weighted_offset_polygons

points = [
    (-1.91, 3.59, 0.0),
    (-5.53, -5.22, 0.0),
    (-0.39, -1.98, 0.0),
    (2.98, -5.51, 0.0),
    (4.83, -2.02, 0.0),
    (9.70, -3.63, 0.0),
    (12.23, 1.25, 0.0),
    (3.42, 0.66, 0.0),
    (2.92, 4.03, 0.0),
    (-1.91, 3.59, 0.0),
]
polygon = Polygon(points)


distances = [0.1, 0.3, 0.6, 0.1, 0.7, 0.5, 0.2, 0.4, 0.8, 0.2]
weights = [1.0 / d for d in distances]
offset = 1.0
offset_polygons_outer = weighted_offset_polygons(points, -offset, weights)

# ==============================================================================
# Viz
# ==============================================================================

viewer = Viewer(width=1600, height=900)
viewer.scene.add(polygon)
viewer.config.renderer.show_grid = False

for opolygon in offset_polygons_outer:
    viewer.scene.add(opolygon, linecolor=(0.0, 0.0, 1.0), facecolor=(1.0, 1.0, 1.0, 0.0))

viewer.show()