Create a matrix of 2-D points. Compute the convex hull and its area.
P = [0 0; 1 1; 1.5 0.5; 1.5 -0.5; 1.25 0.3; 1 0; 1.25 -0.3; 1 -1]; [k,av] = convhull(P);
Plot the original points and the convex hull.
plot(P(:,1),P(:,2),'*') hold on plot(P(k,1),P(k,2))
Display the area.
av = 1.7500
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 = 64.0000
av2 = 64
Points, specified as a matrix whose columns are the x-coordinates, y-coordinates, and (in three dimensions) z-coordinates.
x-coordinates, specified as a column vector.
y-coordinates, specified as a column vector.
z-coordinates, specified as a column vector.
tf— Simplify indicator
Simplify indicator, specified as a numeric or logical
Indices, returned as a vector or matrix.
For 2-D points,
k is a column vector containing the row
indices of the input points that make up the convex hull, arranged
For 3-D points,
k is a 3-column matrix representing a
triangulation that makes up the convex hull. Each row represents a facet of the
triangulation. The values represent the row indices of the input points.
av— Area or volume
Area or volume of the convex hull, returned as a scalar.