我想在R中绘制一个球体,其表面上的网格线使用arcos变换对应于球体的等面积网格。
我一直在试验R包rgl并得到一些帮助:qazxsw poi
其中绘制了具有相等纬度长间距的网格线。
我有下面的函数,它返回一个点的数据框,这是我想要的网格线的交叉点,但不知道如何继续。
Plot points on a sphere in R
任何人都可以提供帮助,总的来说,我发现rgl函数很难处理。
如果你使用plot_sphere <- function(theta_num,phi_num){
theta <- seq(0,2*pi,(2*pi)/(theta_num))
phi <- seq(0,pi,pi/(phi_num))
tmp <- seq(0,2*phi_num,2)/phi_num
phi <- acos(1-tmp)
tmp <- cbind(rep(seq(1,theta_num),each = phi_num),rep(seq(1,phi_num),times = theta_num))
results <- as.data.frame(cbind(theta[tmp[,1]],phi[tmp[,2]]))
names(results) <- c("theta","phi")
results$x <- cos(results$theta)*sin(results$phi)
results$y <- sin(results$theta)*sin(results$phi)
results$z <- cos(results$phi)
return(results)
}
sphere <- plot_sphere(10,10)
或lines3d
,你会得到一个连接数据框中各点的图。要获得中断(您不需要一条长行),请添加包含plot3d(..., type="l")
值的行。
你的NA
函数中的代码看起来真的搞砸了(你计算plot_sphere
两次,你不生成所需长度的向量等),但这个基于它的函数有效:
phi