我正在与一个平面相交,它有 12 个段,它们代表一个立方体的边缘。我遇到的问题是所有交叉点都会产生一个点,即使该点不应该是线段的一部分,因为它们应该是有限的,对吗?
代码:
from sympy import Point3D, Plane, intersection, Segment3D
# Cube's vertices
v = (Point3D(500, 500, 500), Point3D(-500, 500, 500), Point3D(-500, -500, 500),
Point3D(500, -500, 500), Point3D(500, 500, -500), Point3D(-500, 500, -500),
Point3D(-500, -500, -500), Point3D(500, -500, -500))
# Cube´s edges
a = (Segment3D(v[0], v[1]), Segment3D(v[1], v[2]),
Segment3D(v[2], v[3]), Segment3D(v[3], v[0]),
Segment3D(v[0], v[4]), Segment3D(v[1], v[5]),
Segment3D(v[2], v[6]), Segment3D(v[3], v[7]),
Segment3D(v[4], v[5]), Segment3D(v[5], v[6]),
Segment3D(v[6], v[7]), Segment3D(v[7], v[4]))
# Example plane which should generate 3 points
plano = Plane(Point3D(450, 400, 400), Point3D(400, 450, 400), Point3D(400, 400, 450))
bad = []
good = []
for i in range(12):
inter = intersection(plano, a[i])
# This should be executed when the intersection generates anything, but is always executed:
if inter:
bad.append(inter[0])
# This comparation should not be necessary, checks if point is in range desired
if abs(inter[0][0]) <= 500 and abs(inter[0][1]) <= 500 and abs(inter[0][2]) <= 500:
good.append(inter[0])
print(len(bad), bad)
print(len(good), good)
输出:
12 [Point3D(250, 500, 500), Point3D(-500, 1250, 500), Point3D(1250, -500, 500), Point3D(500, 250, 500), Point3D(500, 500, 250), Point3D(-500, 500, 1250), Point3D(-500, -500, 2250), Point3D(500, -500, 1250), Point3D(1250, 500, -500), Point3D(-500, 2250, -500), Point3D(2250, -500, -500), Point3D(500, 1250, -500)]
3 [Point3D(250, 500, 500), Point3D(500, 250, 500), Point3D(500, 500, 250)]
12 个点中有 9 个不属于任何段