Skip to content

Commit c5dcef7

Browse files
author
pv
committed
[DOCS] add polylines simplification example
1 parent 7662a39 commit c5dcef7

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed
66.3 KB
Loading
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import numpy as np
2+
from compas.geometry import Polyline
3+
from compas_viewer import Viewer
4+
from compas_viewer.config import Config
5+
6+
from compas_cgal.polylines import simplify_polyline
7+
8+
9+
# Create a complex polyline: spiral with noise
10+
n_points = 200
11+
t = np.linspace(0, 6 * np.pi, n_points)
12+
radius = 1 + t / 10
13+
noise = np.random.uniform(-0.05, 0.05, n_points)
14+
15+
x = radius * np.cos(t) + noise
16+
y = radius * np.sin(t) + noise
17+
z = t / 5
18+
19+
original_points = np.column_stack([x, y, z])
20+
21+
# Simplify with different thresholds
22+
simplified_high = simplify_polyline(original_points, threshold=0.5)
23+
24+
# Create polylines offset in X for visualization
25+
offset = 6.0
26+
original_polyline = Polyline(original_points.tolist())
27+
simplified_high_polyline = Polyline((simplified_high + [offset, 0, 0]).tolist())
28+
29+
# ==============================================================================
30+
# Visualize
31+
# ==============================================================================
32+
33+
config = Config()
34+
config.camera.target = [5, 0, 5]
35+
config.camera.position = [5, -20, 10]
36+
37+
viewer = Viewer(config=config)
38+
39+
viewer.scene.add(original_polyline, linewidth=2, show_points=False)
40+
viewer.scene.add(simplified_high_polyline, linewidth=3, show_points=False)
41+
42+
viewer.show()
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Polyline Simplification
2+
=======================
3+
4+
This example demonstrates how to simplify polylines using the Douglas-Peucker algorithm in COMPAS CGAL.
5+
6+
Key Features:
7+
8+
* Douglas-Peucker polyline simplification
9+
* XY-plane simplification with Z-coordinate preservation
10+
* Side-by-side visualization of original and simplified polylines
11+
12+
.. figure:: /_images/example_simplify_polylines.png
13+
:figclass: figure
14+
:class: figure-img img-fluid
15+
16+
.. literalinclude:: example_simplify_polylines.py
17+
:language: python

0 commit comments

Comments
 (0)