Products & Services Industries Academia Support User Community Company

Learn more about MATLAB   

voronoi - Voronoi diagram

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 it via delaunay.

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, 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')

voronoi(X,Y,options) specifies a cell array of strings that were previously used by Qhull. Qhull-specific options are no longer required and are currently ignored. Support for these options will be removed in a future release.

convhull uses CGAL, see http://www.cgal.org.

Definition

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.

Visualization

Use one of these methods to plot a Voronoi diagram:

Examples

Example 1

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)

Example 2

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

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 this code to get the figure shown in Example 1.

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

Example 3

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

See Also

DelaunayTri, convhull, delaunay, LineSpec, plot, voronoin

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS