%% Simplify 3-D Convex Hull
% Simplify a 3-D convex hull by removing points that do not affect its volume.
% Create a set of 3-D points. Compute the convex hull and its volume. Plot the convex hull.

[x,y,z] = meshgrid(-2:1:2,-2:1:2,-2:1:2);
x = x(:);
y = y(:);
z = z(:);

[k1,av1] = convhull(x,y,z);

trisurf(k1,x,y,z,'FaceColor','cyan')
axis equal

% Compute and plot a simplified version of the convex hull that contains fewer points, but preserves the volume.

[k2,av2] = convhull(x,y,z,'Simplify',true);

trisurf(k2,x,y,z,'FaceColor','cyan')
axis equal

% Display the volumes of both convex hulls. The volumes are the same, but the simplied convex hull uses fewer points.

av1
av2

% Copyright 2019 The MathWorks, Inc.