Fast Voronoi Diagram in C#






4.93/5 (15 votes)
Fortune Voronoi Diagram in C#
Introduction
This project implements Steve Fortune's algorithm for Voronoi diagram in C#.
I translated the algorithm to C# from Zhenyu Pan's Java version.
The Project
The project is divided into two parts:
- Files: Voronoi.cs, VoronoiElements.cs are the algorithm itself, for your projects, you need these files.
- The program itself is a simple demonstration to test the code and show how it is used.
The project is done in SharpDevelop, EXE file is found in \Voronoi2\bin\Debug\ path.
How to Use the Code in Your Projects
This is very simple, you need the files: Voronoi.cs, VoronoiElements.cs.
In your code, create a "Voronoi
" object.
Create two arrays for X, Y coordinates of any given set of locations.
Use the function "generateVoronoi
", provide the function with those arrays.
For example:
// Create Voronoi Object
Voronoi voroObject = new Voronoi ( Error_Margin_Between_Sites );
// Generate the diagram
List<GraphEdge> ge = voroObject.generateVoronoi ( xVal, yVal, 0, width, 0, height );
// where xVal, yVal are arrays for X,Y coordinates,
// the remaining parameters describe the surrounding box around all the sites
// ge the resulting Voronoi Edges
You get a List of voronoi edges. "ge" in the example.
The code doesn't calculate Voronoi Cells, but having those edges you can do it easily.
References
- What is Voronoi Diagram: https://en.wikipedia.org/wiki/Voronoi
- Orginal Steve Fortune's algorithm written in C, in this page: http://ect.bell-labs.com/who/sjf/
- Original Java code I translated from here: http://sourceforge.net/projects/simplevoronoi/