image thumbnail

lloydsAlgorithm(Px,​Py, crs, numIterations, showPlot)

version 1.6.0.0 (7.16 KB) by Aaron T. Becker's Robot Swarm Lab
Starts with a point set, repeatedly moves each point to centroid of Voronoi cell.

2.1K Downloads

Updated 11 Feb 2015

View License

LLOYDSALGORITHM runs Lloyd's algorithm on the particles at xy positions
(Px,Py) within the boundary polygon crs for numIterations iterations
showPlot = true will display the results graphically.

Lloyd's algorithm starts with an initial distribution of samples or
points and consists of repeatedly executing one relaxation step:
1. The Voronoi diagram of all the points is computed.
2. Each cell of the Voronoi diagram is integrated and the centroid is computed.
3. Each point is then moved to the centroid of its Voronoi cell.
Inspired by http://www.mathworks.com/matlabcentral/fileexchange/34428-voronoilimit
Requires the Polybool function of the mapping toolbox to run.
Run with no input to see example. To initialize a square with 50 robots
in left middle, run:
lloydsAlgorithm(0.01*rand(50,1),zeros(50,1)+1/2, [0,0;0,1;1,1;1,0], 200, true)

Cite As

Aaron T. Becker's Robot Swarm Lab (2021). lloydsAlgorithm(Px,Py, crs, numIterations, showPlot) (https://www.mathworks.com/matlabcentral/fileexchange/41507-lloydsalgorithm-px-py-crs-numiterations-showplot), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2012a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Acknowledgements

Inspired by: VoronoiLimit(varargin)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!