15,876,879 members
Articles / General Programming / Algorithms
Tip/Trick

# Fast Voronoi Diagram in C#

Rate me:
15 Jul 2014CPOL 66.9K   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

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

 First PrevNext
 My vote of 5 Gilles Walther (Giljowal)25-Mar-23 4:09 Gilles Walther (Giljowal) 25-Mar-23 4:09
 My vote of 5 Gilles Walther (Giljowal)25-Mar-23 4:08 Gilles Walther (Giljowal) 25-Mar-23 4:08
 My vote of 5 Ángel Gaspar16-Dec-22 23:34 Ángel Gaspar 16-Dec-22 23:34
 Problems with voronoi generation Member 1493919315-Sep-20 11:05 Member 14939193 15-Sep-20 11:05
 Is there any way to get cell points? Member 1313940511-Jan-18 15:22 Member 13139405 11-Jan-18 15:22
 Great work and one question Marko Goreta13-Nov-16 22:03 Marko Goreta 13-Nov-16 22:03
 Good Job Member 1150660428-Feb-16 12:19 Member 11506604 28-Feb-16 12:19
 How to compute voronoi cells as polygons GeoGecco16-Jul-15 23:53 GeoGecco 16-Jul-15 23:53
 Re: How to compute voronoi cells as polygons adamhancock8-Apr-16 11:58 adamhancock 8-Apr-16 11:58
 very excellent and one question xu19829-Jan-15 18:16 xu1982 9-Jan-15 18:16
 Re: very excellent and one question Burhan Joukhadar16-Mar-15 3:57 Burhan Joukhadar 16-Mar-15 3:57
 EXCELLENT!!! pan0547-Dec-14 8:58 pan054 7-Dec-14 8:58
 Well Done. bwishniak20-Aug-14 10:01 bwishniak 20-Aug-14 10:01
 My vote of 5 AB Yazan Ghoka18-Jul-14 9:40 AB Yazan Ghoka 18-Jul-14 9:40
 Re: My vote of 5 Burhan Joukhadar18-Jul-14 9:49 Burhan Joukhadar 18-Jul-14 9:49
 My vote of 5 TheQult15-Jul-14 23:14 TheQult 15-Jul-14 23:14
 Re: My vote of 5 Burhan Joukhadar18-Jul-14 3:45 Burhan Joukhadar 18-Jul-14 3:45
 My vote of 1 Jackson Savitraz15-Jul-14 20:29 Jackson Savitraz 15-Jul-14 20:29
 Re: My vote of 1 Burhan Joukhadar18-Jul-14 3:37 Burhan Joukhadar 18-Jul-14 3:37
 My vote of 1 .dan.g.15-Jul-14 19:49 .dan.g. 15-Jul-14 19:49
 Re: My vote of 1 Burhan Joukhadar18-Jul-14 3:37 Burhan Joukhadar 18-Jul-14 3:37
 Re: My vote of 1 .dan.g.18-Jul-14 17:16 .dan.g. 18-Jul-14 17:16
 My vote of 1 pstjean15-Jul-14 12:56 pstjean 15-Jul-14 12:56
 Last Visit: 31-Dec-99 18:00     Last Update: 12-Apr-24 5:44 Refresh 12 Next ᐅ