When I use rgl::spheres3d()
, the rendered spheres have clunky facetted edges.
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)
Setting material3d(smooth = TRUE, line_antialias = TRUE)
does not improve this. Increasing the radius does not help either. Is there any way to increase the smoothness with which they are drawn?
A much simpler approach is to use subdivision3d()
. Here, depth=4
isn't all that smooth, but you could increase that.
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")
Here is my approach using 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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With