rgl is a 3D visualization system based on OpenGL. It provides a medium to high level interface for use in R, currently modelled on classic R graphics, with extensions to allow for interaction.
library(rgl)
open3d()
#> glX
#> 1
z <- c(0,0,1)
y <- c(0,1,0)
x <- c(1,0,0)
corner1 <- c(1,1,2,2) # vector entry with corner of square
corner2 <- c(2,3,3,2) # other corner
bg3d(color = "white")
spheres3d(x, y, z, r = 0.2, color = "grey")
quads3d(cbind(0, y[corner1], z[corner2]),
col = "blue", alpha = 0.6)
quads3d(cbind(x[corner1], 0, z[corner2]),
col = 'red', alpha = 0.6)
quads3d(cbind(x[corner1], y[corner2], 0),
col = 'green', alpha = 0.6)
view3d(theta=230, phi=-30, zoom=1, fov=0)
Created on 2024-01-10 with reprex v2.0.2
In R, it is not too bad, but the highlights on the spheres are in the wrong place, as if the light was close to the shape, instead of infinitely distant. But the rglwidget() display is terrible, showing black edges to the spheres.
So far the only workaround I have is to use fov = 0.001 instead of fov = 0; this appears to render correctly.
This example renders incorrectly:
Created on 2024-01-10 with reprex v2.0.2 In R, it is not too bad, but the highlights on the spheres are in the wrong place, as if the light was close to the shape, instead of infinitely distant. But the
rglwidget()
display is terrible, showing black edges to the spheres.So far the only workaround I have is to use
fov = 0.001
instead offov = 0
; this appears to render correctly.