| MATLAB Function Reference | ![]() |
voronoi(x,y)
voronoi(x,y,TRI)
voronoi(X,Y,options)
voronoi(AX,...)
voronoi(...,'LineSpec')
h = voronoi(...)
[vx,vy] = voronoi(...)
Consider a set of coplanar points
. For each point
in the set
, you can draw a boundary enclosing all the intermediate
points lying closer to
than to
other points in the set
. Such a
boundary is called a Voronoi polygon, and the set of
all Voronoi polygons for a given point set is called a Voronoi diagram.
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 it via delaunay.
voronoi(X,Y,options) specifies a cell array of strings to be used as options in Qhull via delaunay.
If options is [], the default delaunay options are used. If options is {''}, no options are used, not even the default.
voronoi(AX,...) plots into AX instead of gca.
voronoi(...,'LineSpec') plots the diagram with color and line style specified.
h = voronoi(...) returns, in h, handles to the line objects created.
[vx,vy] = voronoi(...) returns the finite vertices of the Voronoi edges in vx and vy so that plot(vx,vy,'-',x,y,'.') creates the Voronoi diagram. The lines-to-infinity are the last columns of vx and vy. To ensure the lines-to-infinity do not affect the settings of the axis limits, use the commands:
h = plot(VX,VY,'-',X,Y,'.'); set(h(1:end-1),'xliminclude','off','yliminclude','off')
Note For the topology of the Voronoi diagram, i.e., the vertices for each Voronoi cell, use voronoin. [v,c] = voronoin([x(:) y(:)]) |
Use one of these methods to plot a Voronoi diagram:
If you provide no output argument, voronoi plots the diagram. See Example 1.
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. See Example 2.
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. See Example 3.
This code uses the voronoi function to plot the Voronoi diagram for 10 randomly generated points.
rand('state',5);
x = rand(1,10); y = rand(1,10);
voronoi(x,y)

This code uses the vertices of the finite Voronoi edges to plot the Voronoi diagram for the same 10 points.
rand('state',5);
x = rand(1,10); y = rand(1,10);
[vx, vy] = voronoi(x,y);
plot(x,y,'r+',vx,vy,'b-'); axis equalNote that you can add this code to get the figure shown in Example 1.
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.
rand('state',5);
x=rand(10,2);
[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
axis equal

If you supply no triangulation TRI, the voronoi function performs a Delaunay triangulation of the data that uses Qhull [1]. For information about Qhull, see http://www.qhull.org/. For copyright information, see http://www.qhull.org/COPYING.txt.
convhull, delaunay, LineSpec, plot, voronoin
[1] Barber, C. B., D.P. Dobkin, and H.T. Huhdanpaa,
"The Quickhull Algorithm for Convex Hulls," ACM
Transactions on Mathematical Software, Vol. 22, No. 4, Dec. 1996,
p. 469-483. Available in PDF format at http://www.acm.org/pubs/citations/journals/toms/
1996-22-4/p469-barber/.
![]() | volumebounds | voronoin | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |