雖然rgl::spheres3d()
不能做到這一點unless you edit and rebuild the rgl source,另一種是寫自己的功能繪製領域。這是一個函數,它將球體呈現爲以相等的經度和緯度間隔的四邊形網格。
drawSphere = function(xc=0, yc=0, zc=0, r=1, lats=50L, longs=50L, ...) {
#xc,yc,zc give centre of sphere, r is radius, lats/longs for resolution
vertices = vector(mode = "numeric", length = 12L * lats * longs)
vi = 1L
for(i in 1:lats) {
lat0 = pi * (-0.5 + (i - 1)/lats)
z0 = sin(lat0)*r
zr0 = cos(lat0)*r
lat1 = pi * (-0.5 + i/lats)
z1 = sin(lat1)*r
zr1 = cos(lat1)*r
for(j in 1:longs) {
lng1 = 2 * pi * (j - 1)/longs
lng2 = 2 * pi * (j)/longs
x1 = cos(lng1)
y1 = sin(lng1)
x2 = cos(lng2)
y2 = sin(lng2)
vertices[vi] = x1 * zr0 + xc; vi = vi + 1L
vertices[vi] = y1 * zr0 + yc; vi = vi + 1L
vertices[vi] = z0 + zc; vi = vi + 1L
vertices[vi] = x1 * zr1 + xc; vi = vi + 1L
vertices[vi] = y1 * zr1 + yc; vi = vi + 1L
vertices[vi] = z1 + zc; vi = vi + 1L
vertices[vi] = x2 * zr1 + xc; vi = vi + 1L
vertices[vi] = y2 * zr1 + yc; vi = vi + 1L
vertices[vi] = z1 + zc; vi = vi + 1L
vertices[vi] = x2 * zr0 + xc; vi = vi + 1L
vertices[vi] = y2 * zr0 + yc; vi = vi + 1L
vertices[vi] = z0 + zc; vi = vi + 1L
}
}
indices = 1:(length(vertices)/3)
shade3d(qmesh3d(vertices, indices, homogeneous=F), ...)
}
應當能夠改善這一點,例如使用icospheres(即拉伸該球體作爲拉伸二十面體)。但是如果你讓拉丁和長褲足夠高的話,這個版本已經畫出了相當不錯的球體。
在行動功能的一個例子:
spheres = data.frame(x = c(1,2,3), y = c(1,3,1), z=c(0,0,0), color = c("#992222" , "#222299", "#229922"))
open3d()
material3d(ambient = "black", specular = "grey60", emission = "black", shininess = 30.0)
rgl.clear(type = "lights")
rgl.light(theta = -30, phi = 60, viewpoint.rel = TRUE, ambient = "#FFFFFF", diffuse = "#FFFFFF", specular = "#FFFFFF", x = NULL, y = NULL, z = NULL)
rgl.light(theta = -0, phi = 0, viewpoint.rel = TRUE, diffuse = "gray20", specular = "gray25", ambient = "gray80", x = NULL, y = NULL, z = NULL)
sapply(1:NROW(spheres), function(i)
drawSphere(spheres$x[i], spheres$y[i], spheres$z[i], r=1, lats = 400, longs = 400, color=spheres$color[i]))
![enter image description here](https://i.stack.imgur.com/ZziUU.png)
這是非常好的 - 很好的工作。在n = 101時,赤道附近的脊缺陷仍然存在,但速度和質量之間的折衷很好。隨着n = 201,它已經很難看到。在n = 301時,幾乎沒有明顯的並且仍然可以接受的快速。 – dww
感謝您給我正確的答案投票。願意以rgl的身份獲得銅牌徽章,但以這樣的速度將需要大約10年的時間。 –