planes3d 根据球体半径扩展并绘制区域

问题描述 投票:0回答:1

planes3d 根据球体的半径扩展并绘制区域。有办法抑制这种情况吗?不过,对我来说更理想的是剪切绘图区域。

library(rgl)
z <- c(0,0,1)
y <- c(0,1,0)
x <- c(1,0,0)
bg3d(color = "white")
rgl.spheres(x, y, z, r = 0.02, color = "grey") 
planes3d(1, 0, 0, 0, col = 'blue', alpha = 0.6, size = 0)
planes3d(0, 1, 0, 0, col = 'red', alpha = 0.6, size = 0)
planes3d(0, 0, 1, 0, col = 'green', alpha = 0.6, size = 0)
view3d(theta=230, phi=-30, zoom=1, fov=0)
snapshot3d("r0_02.png", fmt="png", width=640, height=480, webshot=F)

clear3d()
rgl.spheres(x, y, z, r = 0.2, color = "grey") 
planes3d(1, 0, 0, 0, col = 'blue', alpha = 0.6, size = 0)
planes3d(0, 1, 0, 0, col = 'red', alpha = 0.6, size = 0)
planes3d(0, 0, 1, 0, col = 'green', alpha = 0.6, size = 0)
view3d(theta=230, phi=-30, zoom=1, fov=0)
snapshot3d("r0_2.png", fmt="png", width=640, height=480, webshot=F)

我期待一个解决方法。

r rgl
1个回答
0
投票

您不应该使用

planes3d()
,它会绘制无限的平面,并剪裁到边界框。

可能有一种解决方法,您可以将平面放在一个子场景中并在那里应用裁剪,然后将球体放在不同的子场景中而不进行裁剪,但这实现起来很棘手。

更好的方法是使用

quads3d()
而不是
planes3d()
。以你的例子来说,这将是

library(rgl)
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")
rgl.spheres(x, y, z, r = 0.2, color = "grey") 
# planes3d(1, 0, 0, 0, col = 'blue', alpha = 0.6, size = 0)
quads3d(cbind(0, y[corner1], z[corner2]),
        col = "blue", alpha = 0.6)
#planes3d(0, 1, 0, 0, col = 'red', alpha = 0.6, size = 0)
quads3d(cbind(x[corner1], 0, z[corner2]), 
        col = 'red', alpha = 0.6)
#planes3d(0, 0, 1, 0, col = 'green', alpha = 0.6, size = 0)
quads3d(cbind(x[corner1], y[corner2], 0), 
        col = 'green', alpha = 0.6)
view3d(theta=230, phi=-30, zoom=1, fov=0)

创建于 2023-11-30,使用 reprex v2.0.2

我不知道为什么这张图片中的球体渲染得这么差;这看起来像是

rglwidget()
中的一个错误。它不会在 R 中显示,或者如果
fov
设置更改为较小的正数。

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