Created
October 3, 2018 09:40
-
-
Save RCura/dbe100047a57d6c6ee4adc3fc0733773 to your computer and use it in GitHub Desktop.
sector-ize a circle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(sf) | |
# Create the base circle polygon | |
circle <- st_geometry(st_point(c(1E6,1E6))) %>% | |
st_sfc(crs = 2154) %>% | |
st_buffer(dist = 1000) | |
# Create regularly spaced points around polygon | |
perim_points <- circle %>% | |
st_cast("LINESTRING") %>% | |
st_line_sample(n = (360/5)) # The angle of each polygon | |
# Create voronoi around those points and cut it inside the circle | |
sectors <- perim_points %>% | |
st_voronoi(envelope = circle) %>% | |
st_collection_extract("POLYGON") %>% | |
st_intersection(circle) | |
plot(sectors) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment