Click here to Skip to main content
15,867,895 members
Articles / General Programming / Algorithms
Tip/Trick

Fast Voronoi Diagram in C#

Rate me:
Please Sign up or sign in to vote.
4.93/5 (17 votes)
15 Jul 2014CPOL 66.5K   9   26
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:

  1. Files: Voronoi.cs, VoronoiElements.cs are the algorithm itself, for your projects, you need these files.
  2. 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:

C#
// 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

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 5 Pin
Gilles Walther (Giljowal)25-Mar-23 4:09
Gilles Walther (Giljowal)25-Mar-23 4:09 
GeneralMy vote of 5 Pin
Gilles Walther (Giljowal)25-Mar-23 4:08
Gilles Walther (Giljowal)25-Mar-23 4:08 
GeneralMy vote of 5 Pin
Ángel Gaspar16-Dec-22 23:34
Ángel Gaspar16-Dec-22 23:34 
QuestionProblems with voronoi generation Pin
Member 1493919315-Sep-20 11:05
Member 1493919315-Sep-20 11:05 
QuestionIs there any way to get cell points? Pin
Member 1313940511-Jan-18 15:22
Member 1313940511-Jan-18 15:22 
QuestionGreat work and one question Pin
Marko Goreta13-Nov-16 22:03
Marko Goreta13-Nov-16 22:03 
QuestionGood Job Pin
Member 1150660428-Feb-16 12:19
Member 1150660428-Feb-16 12:19 
QuestionHow to compute voronoi cells as polygons Pin
GeoGecco16-Jul-15 23:53
GeoGecco16-Jul-15 23:53 
AnswerRe: How to compute voronoi cells as polygons Pin
adamhancock8-Apr-16 11:58
adamhancock8-Apr-16 11:58 
Questionvery excellent and one question Pin
xu19829-Jan-15 18:16
xu19829-Jan-15 18:16 
AnswerRe: very excellent and one question Pin
Burhan Joukhadar16-Mar-15 3:57
Burhan Joukhadar16-Mar-15 3:57 
GeneralEXCELLENT!!! Pin
pan0547-Dec-14 8:58
pan0547-Dec-14 8:58 
GeneralRe: EXCELLENT!!! Pin
Burhan Joukhadar16-Mar-15 3:07
Burhan Joukhadar16-Mar-15 3:07 
QuestionWell Done. Pin
bwishniak20-Aug-14 10:01
bwishniak20-Aug-14 10:01 
AnswerRe: Well Done. Pin
Burhan Joukhadar21-Aug-14 12:19
Burhan Joukhadar21-Aug-14 12:19 
GeneralMy vote of 5 Pin
AB Yazan Ghoka18-Jul-14 9:40
AB Yazan Ghoka18-Jul-14 9:40 
GeneralRe: My vote of 5 Pin
Burhan Joukhadar18-Jul-14 9:49
Burhan Joukhadar18-Jul-14 9:49 
GeneralMy vote of 5 Pin
TheQult15-Jul-14 23:14
professionalTheQult15-Jul-14 23:14 
GeneralRe: My vote of 5 Pin
Burhan Joukhadar18-Jul-14 3:45
Burhan Joukhadar18-Jul-14 3:45 
GeneralMy vote of 1 Pin
Jackson Savitraz15-Jul-14 20:29
professionalJackson Savitraz15-Jul-14 20:29 
GeneralRe: My vote of 1 Pin
Burhan Joukhadar18-Jul-14 3:37
Burhan Joukhadar18-Jul-14 3:37 
GeneralMy vote of 1 Pin
.dan.g.15-Jul-14 19:49
professional.dan.g.15-Jul-14 19:49 
GeneralRe: My vote of 1 Pin
Burhan Joukhadar18-Jul-14 3:37
Burhan Joukhadar18-Jul-14 3:37 
GeneralRe: My vote of 1 Pin
.dan.g.18-Jul-14 17:16
professional.dan.g.18-Jul-14 17:16 
GeneralMy vote of 1 Pin
pstjean15-Jul-14 12:56
pstjean15-Jul-14 12:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.