Description Usage Details Author(s) Examples
Ear clipping is a relatively cheap method for constrained triangulation of polygons.
1 2 |
Originally this code was published in the 'rgl' package, and written by Duncan Murdoch. The code from rgl 0.99.9 was copied on 2018-01-22.
Duncan Murdoch, in the rgl package
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | data("minimal_mesh", package = "silicate")
rbind_na <- function(x) {
## the inner head-1 is to remove the final closing/start point from simple features
head(do.call(rbind, lapply(x, function(a) rbind(head(a, -1), NA))), -1)
}
strip_sf <- function(x) {
lapply(unlist(lapply(unclass(x), unclass), recursive = FALSE), rbind_na)
}
x <- strip_sf(minimal_mesh$geom)
lapply(x, earclip_rgl)
#ncsf <- sf::read_sf(system.file("shape/nc.shp", package="sf"))
#x <- strip_sf(ncsf$geometry)
#lapply(x, earclip_rgl)
## ## 20s in rgl, 14s with col/rowSums
#rbenchmark::benchmark(lapply(x[1:12], earclip_rgl), replications = 40)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.