how to find the vertices of the convex hull of set of points
15 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Dear all,
I want to check the points in the convex hull, I know how to find the convex hull of the set but I don't know how to find the vertices so I can check them. if anyone have an idea how to do it could he please tell me.
Regards,
Imola
0 commentaires
Réponse acceptée
John D'Errico
le 2 Jan 2015
K = unique(convhull(xy));
Unique is there because one point will be replicated in that list otherwise. If you want it as a polygon, so the first and last points will be the same, then drop the unique.
2 commentaires
John D'Errico
le 3 Jan 2015
Sigh. Before you do silly things, think about what you have, what it means. Look at the output from a computation.
In the code fragment you show in your comment, K IS a list of indexes to the points in the convex hull. Essentially, it already tells you which points are in the convex hull.
If you then try to compute convhull(K), you will get garbage. But why would you bother to do so? Think about what you are doing, rather than trying random things. If you want to look at the coordinates of those points, then
x(K)
y(K)
will suffice. In fact, the code fragment you already have plots EXACTLY those points!
The only thing extra I added was the unique call, since convhull returns a polygon, with the first point repeated at the end of the polygon.
x = rand(1,10);
y = rand(1,10);
K = convhull(x,y)
K =
1
8
6
5
4
1
Thus in the list of points in the plane, (x,y), the convex hull is a polygon that uses points from that set [1 8 6 5 4 1], in THAT ORDER to move around the convex hull polygon.
Unique removes the repeated final point, but it also sorts the indices, so that those points need no longer be in the proper order to form a polygon. Since you asked only for the points which represent the vertices of the convex hull, I gave you the indices which reference that set.
unique(K)
ans =
1
4
5
6
8
Again, IF you want the points in the convex hull as a set of (x,y) pairs, you have already plotted them! The set
x(K),y(K)
is a polygon for the convex hull.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Bounding Regions dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!