# Extract neighbors from first shell of Voronoi tesselation

**URL:** https://discourse.julialang.org/t/extract-neighbors-from-first-shell-of-voronoi-tesselation/42844
**Category:** General Usage
**Tags:** question
**Created:** [July 10, 2020, 12:43pm UTC](https://discourse.julialang.org/t/extract-neighbors-from-first-shell-of-voronoi-tesselation/42844 "2020-07-10T12:43:22Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![cheins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cheins/32/10391_2.png) [@cheins](https://discourse.julialang.org/u/cheins)
#### Post date: [July 10, 2020, 12:43pm UTC](https://discourse.julialang.org/t/extract-neighbors-from-first-shell-of-voronoi-tesselation/42844/1 "2020-07-10T12:43:22Z")

</div>

I’m assuming the best answer to this question requires using `VoronoiDelaunay.jl`, but I’m also open to other packages/approaches.

If I have a set of points in 2D (or 3D? Though not I’m not sure this is possible with the package `VoronoiDelaunay.jl`), what is the fastest way to get each of their nearest neighbors in a Voronoi-tesselation sense (e.g the neighbors within the ‘first Voronoi shell’)? I am also not really confident on the mathematics behind this or how it relates to Delaunay triangulation.

The data structure doesn’t matter too much to me, but let’s just assume the data is stored in a 2D array of type `Array{Float64,2}` called `my_points`, whose size is `(nDims, nPoints),` and `nDims` is 2 or 3, and `nPoints` is the number of points. Let’s say I want to have the output be an edge list of some kind, e.g. array of arrays called `edge_list` (`Array{Array{Int64,1}}`) where each element `i` of `edge_list` gives me the indices of those points that are Voronoi neighbors of the focal point `i` (whose coordinates are stored in `my_points[:,i]`).

 ![Screen Shot 2020-07-10 at 2.26.32 PM](https://global.discourse-cdn.com/julialang/original/3X/a/1/a12aa5647c9e3e20d1ff53a57ee636fae4f3f2b9.png)

---

<div class="post-metadata">

### Author: ![lobingera](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lobingera/32/211_2.png) [@lobingera](https://discourse.julialang.org/u/lobingera)
#### Post date: [July 10, 2020, 1:05pm UTC](https://discourse.julialang.org/t/extract-neighbors-from-first-shell-of-voronoi-tesselation/42844/2 "2020-07-10T13:05:22Z")

</div>

Can you do an example picture? It’s not clear which point you want to address as neighbor.

---

<div class="post-metadata">

### Author: ![cheins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cheins/32/10391_2.png) [@cheins](https://discourse.julialang.org/u/cheins)
#### Post date: [July 10, 2020, 1:17pm UTC](https://discourse.julialang.org/t/extract-neighbors-from-first-shell-of-voronoi-tesselation/42844/3 "2020-07-10T13:17:28Z")

</div>

sure, i’ll add it now!

---

<div class="post-metadata">

### Author: ![lobingera](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lobingera/32/211_2.png) [@lobingera](https://discourse.julialang.org/u/lobingera)
#### Post date: [July 11, 2020, 10:03am UTC](https://discourse.julialang.org/t/extract-neighbors-from-first-shell-of-voronoi-tesselation/42844/4 "2020-07-11T10:03:59Z")

</div>

I did something like this in different context (and not in julia), but it was straight forward: Neighor cells share an edge. So in my case i collected the polygon corners to an index list (match equal x,y) and found candidates that share a corner (index) and then looked left and right if they share an edge. If you need to be really, really fast, you can use the distances between points (that define voronoi cells) to limit the area to test.
