使用 Panda3D 的简单平面相交
Simple plane intersection using Panda3D
在摆弄 Panda3D 看看我是否可以使用它来解决一些简单的几何问题时,我已经完成了这个小测试:
def def_planes_intersect():
"""Intersects the plane defined by the xy and xz axis'."""
xy = Plane()
xz = Plane((LPoint3f(1, 0, 1), LPoint3f(2, 0, 1), LPoint3f(1, 0, 2)))
if xy.intersectsPlane((0, 10, 0), (1, 0, 0), xz) is True:
print("works")
else:
print("doesn't")
它按预期工作,但我不明白如何获取定义交集的 LPoint3f 和 LVector3f。
Panda3D 文档中说:
intersectsPlane(from: LPoint3f, delta: LVector3f, other: LPlanef) → bool
Returns true if the two planes intersect, false if they do not. If they do intersect, then from and delta are filled in with the parametric representation of the line of intersection: that is, from is a point on that line, and delta is a vector showing the direction of the line.
填写from和delta是什么意思?
所以,在写我的问题时,我意识到我必须初始化 LPoint3f 和 LVector3f 的实例,并且该方法会用相关数据填充它们。我决定 post 看到这里可能会有人像我一样迷路
from panda3d.core import LPoint3f, Plane, LVector3f
def def_planes_intersect():
"""Intersects the plane defined by the xy and xz axis'."""
xy = Plane()
xz = Plane((LPoint3f(1, 0, 1), LPoint3f(2, 0, 1), LPoint3f(1, 0, 2)))
a = LPoint3f()
av = LVector3f()
if xy.intersectsPlane(a, av, xz) is True:
print("works")
print(f"{a}\n{av}")
else:
print("doesn't")
打印出明显的结果:
LPoint3f(0, 0, 0)
LVector3f(1, 0, 0)
在摆弄 Panda3D 看看我是否可以使用它来解决一些简单的几何问题时,我已经完成了这个小测试:
def def_planes_intersect():
"""Intersects the plane defined by the xy and xz axis'."""
xy = Plane()
xz = Plane((LPoint3f(1, 0, 1), LPoint3f(2, 0, 1), LPoint3f(1, 0, 2)))
if xy.intersectsPlane((0, 10, 0), (1, 0, 0), xz) is True:
print("works")
else:
print("doesn't")
它按预期工作,但我不明白如何获取定义交集的 LPoint3f 和 LVector3f。
Panda3D 文档中说:
intersectsPlane(from: LPoint3f, delta: LVector3f, other: LPlanef) → bool
Returns true if the two planes intersect, false if they do not. If they do intersect, then from and delta are filled in with the parametric representation of the line of intersection: that is, from is a point on that line, and delta is a vector showing the direction of the line.
填写from和delta是什么意思?
所以,在写我的问题时,我意识到我必须初始化 LPoint3f 和 LVector3f 的实例,并且该方法会用相关数据填充它们。我决定 post 看到这里可能会有人像我一样迷路
from panda3d.core import LPoint3f, Plane, LVector3f
def def_planes_intersect():
"""Intersects the plane defined by the xy and xz axis'."""
xy = Plane()
xz = Plane((LPoint3f(1, 0, 1), LPoint3f(2, 0, 1), LPoint3f(1, 0, 2)))
a = LPoint3f()
av = LVector3f()
if xy.intersectsPlane(a, av, xz) is True:
print("works")
print(f"{a}\n{av}")
else:
print("doesn't")
打印出明显的结果:
LPoint3f(0, 0, 0)
LVector3f(1, 0, 0)