Reputation: 3616
I have used K-means to cluster data into 8 different clusters using this [X,C] = kmeans(XX, 8]
, this means I have 8 centroids where their locations is stored in C
"example shown below X Y Z as coloumns". I want to connect the 8 centroids together where only the centroids of the clusters that are close to each other are connected "have borders between each other" while centroids of clusters that are not close to each other are not connected. So if anyone could please advise?
C=
-0.214560757496055 0.208243029984219 1.27200000000000
-0.170247238295634 0.399735227073470 1.14600000000000
-0.0129089952656497 0.410839908819919 1.22700000000000
-0.244488865509381 0.0526915658425390 1.20200000000000
-0.391215149921094 0.258634052253200 1.23600000000000
-0.258542872172541 0.307469752761704 1.18100000000000
-0.346834999123269 0.413056286165176 1.16100000000000
-0.0885709275819744 0.278674381904261 1.23200000000000
I've used the as suggested but the centroids of some clusters but there are some unwanted connections that are constructed between centroids of non-neighbour clusters "e.g the centroid of the cluster top with the centroids of bottom clusters" as shown in the figure, so if you could please advise
X=C(:,1);
Y=C(:,2);
Z=C(:,3);
dt = DelaunayTri(X,Y,Z);
tetramesh(dt,'FaceColor', 'none');
Upvotes: 0
Views: 633
Reputation: 77454
Just as @Dan commented, you are looking for the Delaunay Triangulation, which is the dual of the Voronoi cells.
See https://en.wikipedia.org/wiki/Delaunay_triangulation for more details.
Image copyright information: https://en.wikipedia.org/wiki/File:Delaunay_Voronoi.png
Black dots are the cluster "centers". Black lines are the Delaunay Triangulation (which is probably what you are looking for) while the red lines and dots are the Voronoi diagram. The usual way to compute the Voronoi digaram actually is to first perform Deleaunay Triangulation, then intersect the orthogonals of nearby edges.
Upvotes: 2