Geometry clustering using K-Means algorithm

本文探讨了几何聚类技术及其在实时图形中的应用。重点介绍了K-means聚类算法的工作原理,并通过实例展示了如何将大量三角形数据归并为几个群组。
部署运行你感兴趣的模型镜像

Geometry clustering is usually useful when an object is supposed to be represented by bill-boards, which is a common technique used in real-time graphics.

 

There are a bunch of clustering algorithms, and "k-means" is one of them, and a relatively simple one, in my opinion. According to "http://en.wikipedia.org/wiki/K-means_clustering", clustering is a NP-hard problem even in 2D plane, so only approximation methods are available. k-means, adopts heuristic strategy to solve it. It seeds by selecting several random triangles(or quad, etc.), then go through each of the rest ones to see which current cluster is the "closest" one [this weighting is what I am investigating for something new], then affiliate it to this cluster, then update the merged cluster.

 

The original version of k-means just uses space distance as the weighting function, like this:

 

 

As the above model "Spruce" shows, more than 12k triangles have been clustered into 8 groups.

 

您可能感兴趣的与本文相关的镜像

Dify

Dify

AI应用
Agent编排

Dify 是一款开源的大语言模型(LLM)应用开发平台,它结合了 后端即服务(Backend as a Service) 和LLMOps 的理念,让开发者能快速、高效地构建和部署生产级的生成式AI应用。 它提供了包含模型兼容支持、Prompt 编排界面、RAG 引擎、Agent 框架、工作流编排等核心技术栈,并且提供了易用的界面和API,让技术和非技术人员都能参与到AI应用的开发过程中

### 如何在 ArcGIS 中使用 K-Means 聚类算法进行空间数据分析 #### 准备工作 要利用ArcGIS实现K-Means聚类分析,需先准备好待分析的空间数据集。这些数据通常为点要素形式存储于Shapefile或其他兼容格式文件内[^1]。 #### 数据预处理 对于导入至ArcGIS平台内的原始地理坐标系下的离散点集合,可能需要执行投影变换以确保所有参与运算的对象处于同一参考框架下;另外还需考虑去除异常值以及标准化数值属性字段以便后续计算过程更加稳定可靠[^4]。 #### 实现方法一:借助 Python Script 工具扩展功能 由于Esri官方并未直接提供内置版本的K-Means工具给桌面端软件调用,因此一种可行方案是编写自定义脚本来完成这项任务。可以采用Python语言配合第三方库如Scikit-Learn来构建模型,并通过arcpy模块接口读取/写入矢量图层对象及其关联表格记录[^2]。 ```python import arcpy from sklearn.cluster import KMeans import numpy as np # 设置环境参数 input_feature_class = "path/to/input_points.shp" output_feature_class = "path/to/output_clusters.shp" # 加载输入特征类并提取几何信息与所需字段值 points = [] fields_to_extract = ["SHAPE@X", "SHAPE@Y"] # 增加其他感兴趣的属性列名 with arcpy.da.SearchCursor(input_feature_class, fields_to_extract) as cursor: for row in cursor: points.append(list(row)) data_array = np.array(points) # 应用K-Means算法 num_clusters = 5 # 定义期望获得的簇数量 kmeans_model = KMeans(n_clusters=num_clusters).fit(data_array) # 将结果保存回新创建的输出Feature Class中 if not arcpy.Exists(output_feature_class): desc = arcpy.Describe(input_feature_class) spatial_reference = desc.spatialReference arcpy.CreateFeatureclass_management( out_path=os.path.dirname(output_feature_class), out_name=os.path.basename(output_feature_class), geometry_type="POINT", template=input_feature_class, spatial_reference=spatial_reference ) with arcpy.da.InsertCursor(output_feature_class, ['SHAPE@', 'CLUSTER_ID']) as icursor: for i, point in enumerate(kmeans_model.labels_): xy = data_array[i][:2] new_point = arcpy.Point(*xy) icursor.insertRow([new_point, int(point)]) ``` 上述代码片段展示了如何基于现有点状要素创建一个新的带有聚类标签的结果图层。 #### 实现方法二:利用 ModelBuilder 构建自动化流程 另一种方式是在ModelBuilder环境中组合多个地理处理组件形成定制化的解决方案。虽然这种方式相对灵活度较低,但对于不具备编程基础的操作人员来说更为直观易懂。具体步骤包括但不限于: - 添加“迭代器”用于遍历指定范围内的候选中心位置; - 插入“近邻统计”算子评估各组成员间的平均距离差异程度; - 配置循环结构直至满足收敛条件为止; - 输出最终形成的类别划分情况可视化图表或报表文档。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值