1. K-Means 聚类原理
目标:把点云分成 KKK 个簇,使簇内点尽量接近簇中心,簇间尽量远。
假设点云:

2、数学原理
优化目标函数

算法步骤

3、Matlab
cpp
clc; clear;
% 生成示例点云
pts1 = randn(50,3) + [1 1 1];
pts2 = randn(50,3) + [3 2 1];
pts3 = randn(50,3) + [2 3 2];
points = [pts1; pts2; pts3];
% 聚类
K = 3;
[idx, C] = kmeans(points, K);
% 可视化
figure; hold on; grid on; axis equal;
colors = lines(K);
for k = 1:K
scatter3(points(idx==k,1), points(idx==k,2), points(idx==k,3), 50, colors(k,:), 'filled');
end
xlabel('X'); ylabel('Y'); zlabel('Z');
title('K-Means 点云聚类示例');
