这里是如何填充国家的方法。
library(maps)
data(worldMapEnv)
world <- map("world", plot = FALSE, fill = TRUE, wrap = c(0, 360))
png("world2D.png", width = 1024L, height = 1024L)
opar <- par(mar = c(0, 0, 0, 0))
plot(world$x, world$y, type = "n", xlab = NA, ylab = NA, axes = FALSE,
xaxs = "i", yaxs = "i", xlim = c(0, 360), ylim = c(-90, 90))
polygon(world$x, world$y, col="orangered", lwd = 2)
par(opar)
dev.off()
![enter image description here](https://istack.dev59.com/viFCY.webp)
library(cgalMeshes)
sphericalCoordinates <- function(θ, ϕ){
x <- cos(θ) * sin(ϕ)
y <- sin(θ) * sin(ϕ)
z <- cos(ϕ)
rbind(x, y, z)
}
rmesh <- parametricMesh(
sphericalCoordinates, urange = c(0, 2*pi), vrange = c(0, pi),
periodic = c(TRUE, TRUE), nu = 1024L, nv = 1024L
)
rmesh$normals <- rmesh$vb[-4L, ]
UV <- cooltools::car2sph(t(rmesh$vb[-4L, ]))
UV <- cbind(UV[, 3L], UV[, 2L])
library(imager)
img <- load.image("world2D.png")
r <- squeeze(R(img))
g <- squeeze(G(img))
b <- squeeze(B(img))
library(cooltools)
x_ <- seq(0, 2*pi, length.out = 1024L)
y_ <- seq(0, pi, length.out = 1024L)
f_r <- approxfun2(x_, y_, r)
f_g <- approxfun2(x_, y_, g)
f_b <- approxfun2(x_, y_, b)
UV_r <- f_r(UV[, 1L], UV[, 2L])
UV_g <- f_g(UV[, 1L], UV[, 2L])
UV_b <- f_b(UV[, 1L], UV[, 2L])
clrs <- rgb(UV_r, UV_g, UV_b)
clrs[clrs == "#FFFFFF"] <- "cyan"
rmesh$material <- list(color = rev(clrs))
library(rgl)
open3d(windowRect = 50 + c(0, 0, 512, 512), zoom = 0.7)
shade3d(rmesh, meshColor = "vertices")
snapshot3d("world3D.png", webshot = FALSE)
![enter image description here](https://istack.dev59.com/GdMez.webp)
rgl::lines3d
。 - Stéphane Laurentlit = FALSE
应该使得两个对cyan
的使用看起来相同。 - user2554330