compas_cgal.straight_skeleton_2
¤
Functions:¤
extrude
¤
extrude(
points, holes=None, weights=None, angles=None, maximum_height=None
) -> tuple[Mesh, list[Line]]
Extrude a 2D polygon into a closed 3D roof mesh using the straight skeleton.
This turns a building footprint into roof-like geometry. Each contour edge sweeps
inwards (and upwards) at a speed controlled by either straight skeleton weights or
taper angles. A uniform weight of 1 (or an angle of 45 degrees) produces a
standard 45 degree hip roof.
The result is ready to display: the returned mesh is triangulated so it renders correctly (even for non-convex roof faces), and the returned lines are the true roof edges (eaves, hips and ridges) to draw on top. A minimal visualization is::
mesh, lines = extrude(polygon, angles=45.0)
viewer.scene.add(mesh, show_lines=False)
for line in lines:
viewer.scene.add(line)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
sequence[point] | :class:`compas.geometry.Polygon`
|
The points of the outer boundary polygon. |
required |
holes
|
sequence[sequence[point]]
|
The holes of the polygon, each as a sequence of points. |
None
|
weights
|
float | sequence
|
Straight skeleton edge weights. A single value applied to every edge, one value
per edge across all contours, or one sequence of edge values per contour
(outer boundary first, then holes). Mutually exclusive with |
None
|
angles
|
float | sequence
|
Taper angles in degrees, following the same shape rules as |
None
|
maximum_height
|
float
|
The maximum extrusion height. If not provided, an inward slope is extruded up to the apex of the skeleton. A maximum height is required for outward or vertical slopes (weights that are negative, or angles of 90 degrees or more). |
None
|
Returns:
| Type | Description |
|---|---|
tuple[:class:`compas.datastructures.Mesh`, list[:class:`compas.geometry.Line`]]
|
The triangulated, closed roof mesh (ready to display with hidden edges), and the roof outline as a list of line segments (eaves, hips and ridges). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If both |
RuntimeError
|
If CGAL fails to extrude the skeleton. |
graph_from_skeleton_data
¤
graph_from_skeleton_data(
points: VerticesNumpy, indices: IntNx1, edges: IntNx2, edge_types: IntNx1
) -> Graph
Create a graph from the skeleton data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
VerticesNumpy
|
The vertices of the skeleton, each vertex defined by 3 spatial coordinates. |
required |
indices
|
IntNx1
|
The vertex indices of the skeleton, corresponding to the points. |
required |
edges
|
IntNx2
|
The edges of the skeleton, each edge defined by 2 vertex indices. |
required |
edge_types
|
IntNx1
|
The type per edge, |
required |
Returns:
| Type | Description |
|---|---|
Graph
|
The skeleton as a graph. |
interior_straight_skeleton
¤
interior_straight_skeleton(
points, as_graph=True
) -> Graph | tuple[VerticesNumpy, IntNx1, IntNx2, IntNx1]
Compute the skeleton of a 2D polygon.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
The points of the polygon. |
required | |
as_graph
|
Whether the skeleton should be returned as a graph, defaults to |
True
|
Returns:
| Type | Description |
|---|---|
Graph | tuple[VerticesNumpy, IntNx1, IntNx2, IntNx1]
|
The skeleton of the polygon. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the normal of the polygon is not directed vertically upwards like [0, 0, 1]. |
interior_straight_skeleton_with_holes
¤
interior_straight_skeleton_with_holes(
points, holes, as_graph=True
) -> Graph | tuple[VerticesNumpy, IntNx1, IntNx2, IntNx1]
Compute the skeleton of a 2D polygon with holes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
The points of the 2D polygon. |
required | |
holes
|
The holes of the polygon. |
required | |
as_graph
|
Whether the skeleton should be returned as a graph, defaults to |
True
|
Returns:
| Type | Description |
|---|---|
Graph | tuple[VerticesNumpy, IntNx1, IntNx2, IntNx1]
|
The skeleton of the polygon. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the normal of the polygon is not directed vertically upwards like [0, 0, 1]. If the normal of a hole is not directed vertically downwards like [0, 0, -1]. |
offset_polygon
¤
Compute the offset from a 2D polygon.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
The points of the 2D polygon. |
required | |
offset
|
The offset distance. If negative, the offset is outside the polygon, otherwise inside. |
required |
Returns:
| Type | Description |
|---|---|
list[Polygon]
|
The offset polygon(s). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the normal of the polygon is not directed vertically upwards like [0, 0, 1]. |
offset_polygon_with_holes
¤
Compute the offset from a 2D polygon with holes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
The points of the 2D polygon. |
required | |
holes
|
The holes of the polygon. |
required | |
offset
|
The offset distance. If negative, the offset is outside the polygon, otherwise inside. |
required |
Returns:
| Type | Description |
|---|---|
list[tuple[Polygon, list[Polygon]]]
|
The polygons with holes. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the normal of the polygon is not directed vertically upwards like [0, 0, 1]. If the normal of a hole is not directed vertically downwards like [0, 0, -1]. |
weighted_offset_polygon
¤
Compute the offset from a 2D polygon with weights.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
The points of the 2D polygon. |
required | |
offset
|
The offset distance. If negative, the offset is outside the polygon, otherwise inside. |
required | |
weights
|
The weights for each edge, starting with the edge between the last and the first point. |
required |
Returns:
| Type | Description |
|---|---|
list[Polygon]
|
The offset polygon(s). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the normal of the polygon is not directed vertically upwards like [0, 0, 1]. |
ValueError
|
If the number of weights does not match the number of points. |