# Documentation

### This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English verison of the page.

# voronoi

Voronoi diagram

### Note

Qhull-specific options are no longer supported. Remove the `OPTIONS` argument from all instances in your code that pass it to `voronoi`.

### Note

The behavior of `h = voronoi(...)` has changed. The new behavior returns a vector of two chart line handles; one representing the points and the other representing the Voronoi edges.

## Syntax

```voronoi(x,y) voronoi(x,y,TRI) voronoi(dt) voronoi(AX,...) voronoi(...,'LineSpec') h = voronoi(...) [vx,vy] = voronoi(...) ```

## Description

`voronoi(x,y)` plots the bounded cells of the Voronoi diagram for the points `x`,`y`. Lines-to-infinity are approximated with an arbitrarily distant endpoint.

`voronoi(x,y,TRI)` uses the triangulation `TRI` instead of computing internally.

`voronoi(dt)` uses the Delaunay triangulation `dt` instead of computing it.

`voronoi(AX,...)` plots into `AX` instead of `gca`.

`voronoi(...,'LineSpec')` plots the diagram with color and line style specified.

`h = voronoi(...)` returns `h`, which is a vector of two chart line handles. One represents the points and the other represents the Voronoi edges.

`[vx,vy] = voronoi(...)` returns the finite vertices of the Voronoi edges in `vx` and `vy`.

### Note

For the topology of the Voronoi diagram, i.e., the vertices for each Voronoi cell, use `voronoin`.

`[v,c] = voronoin([x(:) y(:)])`

## Visualization

Use one of these methods to plot a Voronoi diagram:

• If you provide no output argument, `voronoi` plots the diagram.

• To gain more control over color, line style, and other figure properties, use the syntax `[vx,vy] = voronoi(...)`. This syntax returns the vertices of the finite Voronoi edges, which you can then plot with the `plot` function.

• To fill the cells with color, use `voronoin` with `n = 2` to get the indices of each cell, and then use `patch` and other plot functions to generate the figure. Note that `patch` does not fill unbounded cells with color.

## Examples

collapse all

This code uses the `voronoi` function to plot the Voronoi diagram for 10 randomly generated points.

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

This code uses the vertices of the finite Voronoi edges to plot the Voronoi diagram for the same 10 points used in the previous example.

```x = gallery('uniformdata',[1 10],0); y = gallery('uniformdata',[1 10],1); [vx,vy] = voronoi(x,y); plot(x,y,'r+',vx,vy,'b-') axis equal```

Note that you can add the following code to get the figure shown in the previous example.

```xlim([min(x) max(x)]) ylim([min(y) max(y)])```

This code uses `voronoin` and `patch` to fill the bounded cells of the same Voronoi diagram with color.

```x = gallery('uniformdata',[10 2],5); [v,c] = voronoin(x); for i = 1:length(c) if all(c{i}~=1) % If at least one of the indices is 1, % then it is an open region and we can't % patch that. patch(v(c{i},1),v(c{i},2),i); % use color i. end end```

collapse all

### Voronoi Polygon

Consider a set of coplanar points P. For each point Px in the set P, you can draw a boundary enclosing all the intermediate points lying closer to Px than to other points in the set P. Such a boundary is called a Voronoi polygon.

### Voronoi Diagram

The set of all Voronoi polygons for a given point set is called a Voronoi diagram.