Creating a regular polygon grid over a spatial extent, rotated by a given angle : <p>
Hi all,</p>

<p>I am struggling with this and hope someone could come out with a simple solution.</p>

<p>My objective is to create a regular polygon grid over the extent of a polygon, but <strong>rotated
by a user-defined angle</strong>.</p>

<p>I know that I can easily create a North/South polygon grid in <code>sf</code> using for example:</p>

<pre class="lang-r prettyprint-override"><code>library(sf)
#&gt; Linking to GEOS 3.6.2, GDAL 2.2.3, proj.4 4.9.3
inpoly &lt;- st_read(system.file("shape/nc.shp", package="sf"))[1,] %&gt;% 
  sf::st_transform(3857) %&gt;% 
  sf::st_geometry()
grd &lt;- sf::st_make_grid(inpoly, cellsize = 3000)
plot(inpoly, col = "blue")
plot(grd, add = TRUE)
</code></pre>

<p><img src="https://i.imgur.com/WUx6ssr.png" alt=""></p>

<p>I also know that I can easily rotate it by a given angle using:</p>

<pre class="lang-r prettyprint-override"><code>rotang = 20
rot = function(a) matrix(c(cos(a), sin(a), -sin(a), cos(a)), 2, 2)
grd_rot &lt;- (grd - st_centroid(st_union(grd))) * rot(rotang * pi / 180) +
  st_centroid(st_union(grd))
plot(inpoly, col = "blue")
plot(grd_rot, add = TRUE)
</code></pre>

<p><img src="https://i.imgur.com/lCtXWlB.png" alt=""></p>

<p>My problem is that , depending on the rotation angle, the general “orientation”
of the input polygon and the cell size, <strong>the rotated grid may not cover anymore the full extent of the
polygon</strong>, as shown below:</p>

<pre class="lang-r prettyprint-override"><code>rotang = 45
rot = function(a) matrix(c(cos(a), sin(a), -sin(a), cos(a)), 2, 2)
grd_rot &lt;- (grd - st_centroid(st_union(grd))) * rot(rotang * pi / 180) +
  st_centroid(st_union(grd))
plot(inpoly, col = "blue")
plot(grd_rot, add = TRUE)
</code></pre>

<p><img src="https://i.imgur.com/YYgk9pA.png" alt=""></p>

<p>Any clever idea about how I could address this issue and <strong>create a rotated grid fully covering the polygon</strong> (besides by creating a larger
grid to start with, which is quite inefficient for small cellsizes?)? </p>

<p>Either <code>sf</code> or <code>sp</code> solutions would be welcome. “Bonus points” if it is possible
to make the grid start at one of the extreme vertexes of the polygon (i.e., the
first line of the grid “touches” the northern vertex of the polygon), but that is not "mandatory". </p>

<p>Created on 2018-07-11 by the <a href="http://reprex.tidyverse.org" rel="noreferrer">reprex package</a> (v0.2.0).</p>
