Find the centers of multiple polygons

2 views (last 30 days)
Jeremy
Jeremy on 3 Jul 2014
Commented: Image Analyst on 3 Jul 2014
I have an nx3 matrix that holds the locations for the vertices of a chain of hexagonal shapes (images 1, 2).
Side-note: The coordinates for the vertices of these hexagons are not in any logical order within the matrix. The coordinates were retrieved from an STL file which may be the reason why.
I'm trying to find the centroid of each of these hexagons and index those six points to its respective centroid. Once I've indexed these, I plan on writing some more code to manipulate the six points farther away from their respective centroids - making the hexagons larger and making my structure thicker [ they are currently too thin ] (image 3).
My problem is the centroid and indexing part. I've tried clustering the hexagons into n/6 clusters using the k-means and subclust functions, but there're always points that do not fall in the center of a hexagon (image 4).
Would anyone know what I should try?
[I've also attached the matrix, in case you would like to play around with the data as well.]

Answers (1)

Image Analyst
Image Analyst on 3 Jul 2014
Isn't the centroid of a perfect hexagon just the mean of the x and y coordinates of the vertices?
xCentroid = mean(xVertices);
yCentroid = mean(yVertices);
Just do that for every hexagon and you'll have all the centroids.
  4 Comments
Jeremy
Jeremy on 3 Jul 2014
Yes. The data was imported from an STL file, where I presume the random ordering is necessary to construct mesh/surface type objects. Any ideas?

Sign in to comment.

Categories

Find more on Statistics and Machine Learning Toolbox in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!