Skip to content

compas_cgal.polylines ¤

Polyline utilities using CGAL.

Functions¤

closest_points_on_polyline ¤

closest_points_on_polyline(query_points: PointsList, polyline: PointsList) -> NDArray

Find closest points on a polyline for a batch of query points.

Uses CGAL's AABB tree for efficient batch queries.

Parameters:

Name Type Description Default
query_points PointsList

Query points as Mx2 or Mx3 array.

required
polyline PointsList

Polyline as Nx2 or Nx3 array.

required

Returns:

Type Description
ndarray

Closest points on the polyline (same shape as query_points).

Examples:

>>> polyline = [[0, 0], [10, 0]]
>>> queries = [[5, 5], [3, -2]]
>>> closest = closest_points_on_polyline(queries, polyline)
>>> closest[0]  # Closest to (5, 5) on horizontal line
array([5., 0.])

simplify_polyline ¤

simplify_polyline(polyline: PointsList, threshold: float) -> NDArray

Simplify a single polyline using Douglas-Peucker algorithm.

Simplification is performed in the XY plane only. For 3D polylines, Z coordinates are preserved but not considered in distance calculations.

Parameters:

Name Type Description Default
polyline PointsList

Sequence of 2D or 3D points.

required
threshold float

Distance threshold for simplification.

required

Returns:

Type Description
ndarray

Simplified polyline as numpy array.

simplify_polylines ¤

simplify_polylines(polylines: list[PointsList], threshold: float) -> list[NDArray]

Simplify multiple polylines using Douglas-Peucker algorithm.

Simplification is performed in the XY plane only. For 3D polylines, Z coordinates are preserved but not considered in distance calculations.

Parameters:

Name Type Description Default
polylines list[PointsList]

List of polylines. Each polyline is a sequence of 2D or 3D points.

required
threshold float

Distance threshold for simplification. Higher values remove more points.

required

Returns:

Type Description
list of ndarray

Simplified polylines as numpy arrays.

Examples:

>>> polylines = [[[0, 0], [1, 0.01], [2, 0]], [[0, 0], [0, 1], [1, 1]]]
>>> simplified = simplify_polylines(polylines, threshold=0.1)
>>> len(simplified[0])  # First polyline simplified
2
>>> len(simplified[1])  # Second has corner, preserved
3