title: How to get Voronoi diagram around polygons
body: <p>I would like to generate a <a href="https://en.wikipedia.org/wiki/Voronoi_diagram" rel="nofollow noreferrer">Voronoi diagram</a> around 2D polygons. This question is somehow similar to <a href="https://stackoverflow.com/questions/36015521/generating-a-voronoi-diagram-around-2d-polygons">this one here</a> addressed for Python.</p>
  
  <p>Is straightforward how this works for points, below is an example with <code>sf::st_voronoi()</code> function:</p>
  
  
  
  <pre class="lang-r prettyprint-override"><code>library(sf)
  #&gt; Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
  
  p &lt;- rbind(c(3.2,4),
             c(3,4.6),
             c(3.8,4.4),
             c(3.5,3.8),
             c(3.4,3.6),
             c(3.9,4.5))
  
  plot(p, pch = 16)
  p %&gt;% st_multipoint() %&gt;% st_voronoi() %&gt;% plot(col = NA, add = TRUE)
  </code></pre>
  
  <p><img src="https://i.imgur.com/CGJlCYb.png" alt=""></p>
  
  <p><sup>Created on 2020-05-28 by the <a href="https://reprex.tidyverse.org" rel="nofollow noreferrer">reprex package</a> (v0.3.0)</sup></p>
  
  <p>But when I try the same function for some generated polygons, I do not get the results I would like:</p>
  
  
  
  <pre class="lang-r prettyprint-override"><code>library(sf)
  #&gt; Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
  
  p1 &lt;- rbind(c(0,0), c(1,0), c(3,2), c(2,4), c(1,4), c(0,0))
  p2 &lt;- rbind(c(3,0), c(4,0), c(4,1), c(3,1), c(3,0))
  
  pol &lt;- st_multipolygon(list(list(p1), list(p2)))
  
  plot(st_voronoi(pol), col = NA, lwd = 2, lty = 3)
  plot(pol, col = rgb(1,0,0, alpha = 0.3), add = TRUE)
  </code></pre>
  
  <p><img src="https://i.imgur.com/2eBqgPr.png" alt=""></p>
  
  <p><sup>Created on 2020-05-28 by the <a href="https://reprex.tidyverse.org" rel="nofollow noreferrer">reprex package</a> (v0.3.0)</sup></p>
  
  <p>It seems that the Voronoi grid is based on the vertices of the polygons, which makes sense. However, I would like to get a Voronoi grid surrounding the red polygons and not intersecting them, that is, to treat a polygon as a point. Note that, getting the centroids of the polygons (e.g. with <code>sf::st_centroid</code>) and then generating a Voronoi grid is a path I tried, but the Voronoi grid will still intersect the polygons.</p>