Skip to content

Instantly share code, notes, and snippets.

@mdsumner
Last active September 4, 2019 19:54
Show Gist options
  • Save mdsumner/c20c31b938a6208d7499242e5df8a335 to your computer and use it in GitHub Desktop.
Save mdsumner/c20c31b938a6208d7499242e5df8a335 to your computer and use it in GitHub Desktop.
Mesh plot with raster / quadmesh, and types of meshes
## latest needed for recent bug fix in triangles
## remotes::install_github("hypertidy/quadmesh")
library(quadmesh)
r <- quadmesh::etopo
## volcano as a raster in 0:nr, 0:nc (just because it's small and familiar)
v <- raster::raster(volcano, xmn = 0, xmx = nrow(volcano), ymn = 0, ymx = ncol(volcano))
v <- raster::aggregate(v, fact = 2)
## 2D plot in any projection
mesh_plot(r, crs = "+proj=laea +lon_0=147 +lat_0=-42 +datum=WGS84", asp = 1)
## continuous mesh3d (quads, slightly nonsense in continous terms ...)
rgl::clear3d(); rgl::wire3d(quadmesh(v)); rgl::aspect3d(1, 1, 0.4); rgl::rglwidget()
## discrete mesh3d (quads constant height at cell value)
rgl::clear3d(); rgl::wire3d(dquadmesh(v)); rgl::aspect3d(1, 1, 0.4); rgl::rglwidget()
## continuous mesh3d (triangle corners at raster cell centre value)
rgl::clear3d();rgl::wire3d(triangmesh(v)); rgl::aspect3d(1, 1, 0.4); rgl::rglwidget()
## discrete mesh3d (triangle constant height at the mean their corners)
rgl::clear3d();rgl::wire3d(dtriangmesh(v)); rgl::aspect3d(1, 1, 0.4); rgl::rglwidget()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment