On 21/10/2020 8:45 a.m., Balint Radics wrote:
Hello,

Could someone suggest a package/way to make a 3D raster plot of the Earth
(with continent boundaries), and then make a "cut" or "slice" of it such
that one can also visualize some scalar quantity as a function of the
Radius/Depth across that given slice ?

Formally, I would have a given, fixed longitude, and a list of vectors
{latitude, radius, Value}
that would show the distribution of the quantity "Value" at various depths
and latitudes in 3D.

The rgl package has a full sphere of the Earth with (obsolete) political boundaries in example(persp3d). To cut it in half along the plane through a given longitude (and that longitude + 180 deg), you could use clipPlanes3d, or clipObj3d. For example,

library(rgl)
lat <- matrix(seq(90, -90, len = 50)*pi/180, 50, 50, byrow = TRUE)
long <- matrix(seq(-180, 180, len = 50)*pi/180, 50, 50)

r <- 6378.1 # radius of Earth in km
x <- r*cos(lat)*cos(long)
y <- r*cos(lat)*sin(long)
z <- r*sin(lat)

open3d()
ids <- persp3d(x, y, z, col = "white",
        texture = system.file("textures/worldsmall.png", package = "rgl"),
specular = "black", axes = FALSE, box = FALSE, xlab = "", ylab = "", zlab = "",
        normal_x = x, normal_y = y, normal_z = z)

clipFn <- function(coords) {
  pmax(coords[,1], coords[,2]) # Just an example...
}
clipObj3d(ids["surface"], clipFn)


Filling in the exposed surface could be done with polygon3d(), with some work to construct the polygon. Displaying the function across that surface could be done in a couple of ways, either by using a texture map (like for the map), or subdividing the polygon and setting colour by the coordinates of each vertex.

Note that the clipObj3d function isn't on CRAN yet; there you'd have to use clipPlanes3d. You can get the newer version from R-forge.

Duncan Murdoch

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to