Clustering

Clustering module: ezdxf.math.clustering

ezdxf.math.clustering.average_cluster_radius(clusters: List[List[Union[Vec2, Vec3]]]) float

Returns the average cluster radius.

ezdxf.math.clustering.average_intra_cluster_distance(clusters: List[List[Union[Vec2, Vec3]]]) float

Returns the average point-to-point intra cluster distance.

ezdxf.math.clustering.dbscan(points: List[Union[Vec2, Vec3]], *, radius: float, min_points: int = 4, rtree: Optional[RTree] = None, max_node_size: int = 5) List[List[Union[Vec2, Vec3]]]

DBSCAN clustering.

https://en.wikipedia.org/wiki/DBSCAN

Parameters
  • points – list of points to cluster

  • radius – radius of the dense regions

  • min_points – minimum number of points that needs to be within the radius for a point to be a core point (must be >= 2)

  • rtree – optional RTree

  • max_node_size – max node size for internally created RTree

Returns

list of clusters, each cluster is a list of points

New in version 0.18.

ezdxf.math.clustering.k_means(points: List[Union[Vec2, Vec3]], k: int, max_iter: int = 10) List[List[Union[Vec2, Vec3]]]

K-means clustering.

https://en.wikipedia.org/wiki/K-means_clustering

Parameters
  • points – list of points to cluster

  • k – number of clusters

  • max_iter – max iterations

Returns

list of clusters, each cluster is a list of points

New in version 0.18.