anglr
anglr copied to clipboard
scatter dem
This is fun, mesh a set of points in xy and plot in rgl or as 2D, options:
- control max area
a, and othe rproperties ofRTriangle::triangulateeg.Dfor Delaunay criterion - if z is included any Steiner points are automatically interpolated
scatter_dem <- function(x, y = NULL, z = NULL, ...) {
x <- xy.coords(x, y)
x <- cbind(x$x, x$y)
PA <- NA
if (!is.null(z)) {
PA <- matrix(z, nrow = nrow(x))
}
p <- RTriangle::pslg(x, PA = PA)
anglr::as.mesh3d(RTriangle::triangulate(p, ...))
}
library(raster)
library(rgl)
n <- 5000
r <- quadmesh::etopo
x <- cbind(runif(n, -180, 180),
runif(n, -90, 90))
x <- raster::xyFromCell(r, sample(1:ncell(r), n))
clear3d()
mesh_plot(
dem <- scatter_dem(x, z = raster::extract(r, x), a = .5, D = TRUE)
)
plot3d(dem)
auto_3d(z = 30)
This should go into guerrilla