有限同情段的错误
Bug with finite sympy segments
我正在与一个具有 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 个不属于任何线段
目前这是一个错误(在 sympy 1.4 或早期版本中),将在 1.5 版本中修复。
https://github.com/sympy/sympy/pull/16637
这已在 SymPy master 上修复,但修复尚未在发布版本中。在 master 上我得到:
3 [Point3D(250, 500, 500), Point3D(500, 250, 500), Point3D(500, 500, 250)]
3 [Point3D(250, 500, 500), Point3D(500, 250, 500), Point3D(500, 500, 250)]
(我假设这就是您所期望的)
我正在与一个具有 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 个不属于任何线段
目前这是一个错误(在 sympy 1.4 或早期版本中),将在 1.5 版本中修复。 https://github.com/sympy/sympy/pull/16637
这已在 SymPy master 上修复,但修复尚未在发布版本中。在 master 上我得到:
3 [Point3D(250, 500, 500), Point3D(500, 250, 500), Point3D(500, 500, 250)]
3 [Point3D(250, 500, 500), Point3D(500, 250, 500), Point3D(500, 500, 250)]
(我假设这就是您所期望的)