首页 > 解决方案 > rgl:绘制由两个 3D 向量跨越的平面

问题描述

我无法理解rgl::plane3d绘制由两个向量(x0x1)跨越的平面所需的参数,通过给定点(O =origin)。这是一个解释投影的图表。

rgl 文档没有提供足够的示例让我理解要指定的内容。

在此处输入图像描述

这是我的 MWE:

library(matlib)
library(rgl)
rgl::open3d()
O <- c(0, 0, 0)
x0 <- c(1, 1, 1)
x1 <- c(0, 1, 1)
y <- c(1, 1, 3)
XX <- rbind(x0=x0, x1=x1)
matlib::vectors3d(XX, lwd=2)
matlib::vectors3d(y, labels=c("", "y"), color="red", lwd=3)
# how to specify the plane spanned by x0, x1 ???
# planes3d(..., col="gray",  alpha=0.2)
# draw projection of y on plane of XX
py <-  matlib::Proj(y, t(XX))
rgl::segments3d(rbind( y, py))
rgl::segments3d(rbind( O, py))

标签: rprojectionrglplane

解决方案


要找到平行于 x0 和 x1 的平面,求这两个向量的叉积,我们可以手动完成,因为它是 R:

library(pracma)
cross(x1,x2)
[1]  0 -1  1

因此,与此垂直的平面方程基本上是任何点积将为您提供 0 的向量,这意味着:

0*x + -1*y + 1*z = 0
-y + z = 0

你可以阅读更多关于这里的解释。或者在您的场景中,您可以将其视为需要 ay = z 平面(因为 x 不同)。

因此,如果您查看文档,它会说:

'planes3d' 和 'rgl.planes' 使用参数化 ax + by + cz + d = 0 绘制平面。

我们没有偏移量,所以 d = 0,这给我们留下了 a = 0、b= -1 和 c= 1:

plot3d(rbind(0,x1),type="l",xlim=c(0,3),ylim=c(0,3),
zlim=c(0,3),xlab="x",ylab="y",zlab="z")
lines3d(rbind(0,y),col="red")
lines3d(rbind(0,x0))

py <-  matlib::Proj(y, t(XX))
segments3d(rbind( y, py),col="gray")
segments3d(rbind( O, py),col="gray")

planes3d(a=0,b=-1,c=1,col="turquoise",alpha=0.2)

在此处输入图像描述

在此处输入图像描述


推荐阅读