如何增加rgl中spheres3d的光滑度

dww*_*dww 7 r rgl

当我使用时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)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

设置material3d(smooth = TRUE, line_antialias = TRUE)不会改善这一点.增加半径也无济于事.有没有办法增加它们的平滑度?

Mik*_*ise 2

扩展cuttlefish44 的出色答案,我发现了一种效果更好的参数化 - 即它在两极没有缺陷(图像中浅蓝色球体上的黑色伪影)。

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")
Run Code Online (Sandbox Code Playgroud)

图片:

在此输入图像描述