如何提高RGL spheres3d的平滑

问题描述 投票:7回答:6

当我使用qazxsw POI,渲染领域有多方面矮胖的边缘。

rgl::spheres3d()

spheres = data.frame(x = c(1,2,3), y = c(1,3,1), color = c("#992222" , "#222299", "#229922")) open3d() spheres3d(spheres$x, spheres$y, radius = 1, color = spheres$color)

设置enter image description here不改善这一点。增加半径也没有帮助。有什么办法来增加与它们绘制的平滑度?

r rgl
6个回答
1
投票

扩展在material3d(smooth = TRUE, line_antialias = TRUE),我发现,工作得更好参数化 - 即它具有在两极没有缺陷(在图像中的lightblue领域的黑色神器)。

cuttlefish44's excellent answer

图片:

library(rgl) sphere.f <- function(x0 = 0, y0 = 0, z0 = 0, r = 1, n = 101, ...){ f <- function(s, t) cbind(r * cos(s) * cos(t) + x0, r * sin(s) * cos(t) + y0, r * sin(t) + z0) persp3d(f, slim = c(0, pi), tlim = c(0, 2*pi), n = n, add = T, ...) } sphere1.f <- function(x0 = 0, y0 = 0, z0 = 0, r = 1, n = 101, ...){ f <- function(s,t){ cbind( r * cos(t)*cos(s) + x0, r * sin(s) + y0, r * sin(t)*cos(s) + z0) } persp3d(f, slim = c(-pi/2,pi/2), tlim = c(0, 2*pi), n = n, add = T, ...) } sphere.f( -1.5,0, col = "lightblue") sphere1.f( 1.5,0, col = "pink")


3
投票

一个更简单的方法是使用enter image description here。在这里,subdivision3d()是不是所有的顺利,但你可以增加。

depth=4

library(rgl) sphere <- subdivision3d(cube3d(),depth=4) sphere$vb[4,] <- apply(sphere$vb[1:3,], 2, function(x) sqrt(sum(x^2))) open3d() shade3d(sphere, col="red")


3
投票

虽然enter image description here不能做到这一点,另一种是写自己的函数来绘制球体。这里是呈现一个球体作为在等于纬度和经度的间隔四边形网格的函数。

rgl::spheres3d()

应该可能使用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]))


2
投票

这并不容易;我认为,如果你想这样做你将不得不

src/sphereSet.cpp

调用函数的一些较大的值(该功能上sphereMesh.setGlobe(16,16); 的线25所定义;所述参数是src/SphereMesh.cppin_segments ...)

  • 建立/从源安装的软件包;这不仅需要标准的编译工具,而且相关的OpenGL库(在Debian的Linux操作系统,你可以使用in_sections得到他们,我想...)

我没有尝试这样做。祝你好运......或者,你可以问清楚包的维护者,使这个通过sudo apt-get build-dep r-cran-rgl或以其他方式可设置参数...


2
投票

下面是使用materials3d我的方法

persp3d.function()

sphere.f <- function(x0 = 0, y0 = 0, z0 = 0, r = 1, n = 101, ...){ f <- function(s, t) cbind(r * cos(s) * cos(t) + x0, r * sin(s) * cos(t) + y0, r * sin(t) + z0) persp3d(f, slim = c(0, pi), tlim = c(0, 2*pi), n = n, add = T, ...) } sphere.f(col = rainbow)


0
投票

另一种可能性是使用enter image description here包的vcgSphere功能。

Rvcg

library(Rvcg) sphr <- vcgSphere(subdivision = 4) # unit sphere centered at (0,0,0) library(rgl) shade3d(sphr, color="red") # sphere with given radius and center radius <- 0.5 center <- c(2,1,1) sphr2 <- translate3d( scale3d(sphr, radius, radius, radius), center[1], center[2], center[3]) shade3d(sphr2, color="green")

© www.soinside.com 2019 - 2024. All rights reserved.