DailyInformation
DailyInformation

Reputation: 1

Matlab: what is the correct way to get the convex hull

I have a 3D array of data which shows one concave figure. I want to find all points which don't belong to the figure, but are inside the convex hull. How can I do it?

I know I should use the convhull function, but I'm not sure how (the input is an array of size m by n, where m is the number of points and n is the number of dimensions, so 3 in my case). Also, I'm not sure how to process the output of this function - it has the same size as the input matrix.

I'd appreciate any examples.

Upvotes: 0

Views: 425

Answers (1)

Adriaan
Adriaan

Reputation: 18187

[K, V] = convhull(YourArray);

K are the indices of your points corresponding to the points on the convex hull, V is just the volume spanned by that convex hull. Thus, you can use this row index to find your points back in YourArray.

Using the below example:

YourArray= rand(1e3,3);
[K, V] = convhull(YourArray);

K gave me a 140x3 'double' containing the indices of my points and V=0.9291, the volume spanned by my convex hull. You can get the points on the convex hull back from YourArray by simply calling

YourArray(K)

Documentation link

Unsurprisingly more people have struggled with obtaining the points within the convex hull and have actually written code for this, see the MathWorks Central, code by John D'Errico.

Upvotes: 1

Related Questions