voronoi_spherical.Rd
Generate a Voronoi mesh on spherical coordinates
voronoi_spherical(xyz)
xyz | matrix of columns longitude, latitude, and optionally z |
---|
list with matrix elements triangles
, edges
and centroids
.
An input matrix of XYZ coordinates is triangulated using convex hull (Delaunay on the sphere), coordinates are assumed to lie on the surface of a sphere.
A list is returned with triangles
the index of triangles created from xyz
,
$edges
a matrix of index pairs into $centroids
, a matrix
of XYZ coordinates that are the centres of the triangles of the convex hull of xyz
.
## does the hard work (convex hull on xyz points is Delaunay triangulation) library(geometry) ## random longlat coordinates on the (geo)sphere pts <- geosphere::randomCoordinates(5000) library(rgl)#> Error: package or namespace load failed for ‘rgl’: #> .onLoad failed in loadNamespace() for 'rgl', details: #> call: NULL #> error: X11 not found; XQuartz (from www.xquartz.org) is required to run rgl.#> Error in clear3d(): could not find function "clear3d"#> Error in segments3d(vs$centroids[t(vs$edges), ], lit = FALSE, lwd = 2): could not find function "segments3d"#> Error in spheres3d(0, 0, 0, 6310000, color = "lightgrey"): could not find function "spheres3d"## add the triangles wire3d(tmesh3d(t(ll2cart(pts, rad = 6350000)), t(vs$triangles), homogeneous = FALSE), color = grey(0.3), alpha = .8)#> Error in wire3d(tmesh3d(t(ll2cart(pts, rad = 6350000)), t(vs$triangles), homogeneous = FALSE), color = grey(0.3), alpha = 0.8): could not find function "wire3d"#pts <- do.call(cbind, maps::map(plot = FALSE)[c("x", "y")]) #pts <- pts[!is.na(pts[,1]), ] #pts <- pts[sort(sample(1:nrow(pts), 8000)), ]