1 min read

3d stuff

This is an example pasted from http://www.stats.uwo.ca/faculty/murdoch/Western2015/rgl2015.html#14

library(rgl)
## Warning: package 'rgl' was built under R version 3.4.4
invisible(open3d())
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)
cols <- c(rep("chocolate4",4), rep("burlywood1", 4), "darkgoldenrod1")
rs <- c(6350, 5639, 4928.5, 4207, 3486, 
                         (3486+2351)/2, 2351, (2351+1216)/2, 1216)
obj <- c(persp3d(x, y, z, col="white", 
          texture=system.file("textures/world.png",package="rgl"), 
          specular="black", axes=FALSE, box=FALSE, 
          xlab="", ylab="", zlab="",
          normal_x=x, normal_y=y, normal_z=z),
         spheres3d(matrix(0, 9, 3), col = cols, radius = rs))
rglwidget(elementId = "earth")