r - rgl:绘制由两个 3D 向量跨越的平面
问题描述
我无法理解rgl::plane3d
绘制由两个向量(x0,x1)跨越的平面所需的参数,通过给定点(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))
解决方案
要找到平行于 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)
推荐阅读
- javascript - 如何在NodeJS中的回调函数中设置全局变量的值
- flutter - 使用flutter_form_builder包实现FormBuilderChoiceChip的正确方法是什么?
- java - IF 语句的 Java 问题
- node.js - MongoError:E11000 重复键错误集合:myFirstDatabase.tours 索引:rating_1 重复键:{ rating:null }
- flutter - 如何正确保存上传到 Flutter Android 应用程序的图像?
- javascript - 如何通过函数设置属性的值?
- jquery - 如何禁用悬停下拉菜单(wordpress)?
- r - 输出 TRUE 值
- django - Django - 数据库
- typescript - 如何优化 npm start 的过程,使其在给定依赖项下尽可能快?