how to find the vertices of the convex hull of set of points
15 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
John D'Errico
on 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 Comments
John D'Errico
on 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.
More Answers (0)
See Also
Categories
Find more on Bounding Regions 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!