Accelerating the pace of engineering and science

• Trials

# convexHull

Class: delaunayTriangulation

## Syntax

K = convexHull(DT)
[K,v] = convexHull(DT)

## Description

K = convexHull(DT) returns the vertices of the convex hull.

[K,v] = convexHull(DT) also returns the area or volume bounded by the convex hull.

## Input Arguments

 DT A Delaunay triangulation, see delaunayTriangulation.

## Output Arguments

 K Convex hull vertices, returned as a matrix of vertex IDs. The shape of K depends on whether your triangulation is 2-D or 3-D:When DT is 2-D, K is a column vector containing the sequence of vertex IDs around the convex hull.When DT is 3-D, K is a triangulation connectivity list containing the triangles on the convex hull. v Area or volume bounded by the convex hull, returned as a scalar value.

## Definitions

### Vertex ID

A row number of the matrix, DT.Points. Use this ID to refer a specific vertex in the triangulation.

## Examples

expand all

### Convex Hull in 2-D Space

Create a Delaunay triangulation from a set of random points.

```x = gallery('uniformdata',[10,1],0);
y = gallery('uniformdata',[10,1],1);
DT = delaunayTriangulation(x,y);
```

Calculate the convex hull.

```k = convexHull(DT)
```
```k =

1
3
2
8
9
1

```

Plot the points and highlight the convex hull in red.

```plot(DT.Points(:,1),DT.Points(:,2), '.','markersize',10);
hold on;
plot(DT.Points(k,1),DT.Points(k,2),'r');
hold off;
```

### Convex Hull in 3-D Space

Use convexHull to calculate the convex hull of a set of random points within a unit cube.

Create a Delaunay triangulation from a set of random points.

```P = gallery('uniformdata',[25,3],1);
DT = delaunayTriangulation(P);
```

Calculate the convex hull and the volume bounded by the convex hull.

```[K,v] = convexHull(DT);
```

Examine the volume.

```v
```
```v =

0.3561

```

Plot the convex hull.

```trisurf(K,DT.Points(:,1),DT.Points(:,2),DT.Points(:,3),...
'FaceColor','cyan')
```