Geometry3D
Geometry3D copied to clipboard
Error when getting the intersection of 2 Convex Polyhedrons
Hi there, I am using your library to check whether 2 convex polyhedrons intersect each other. The library has worked for many of these polyhedrons before, but I'm now getting a value error when checking some intersections. Here is the stack trace:
File python3.11/site-packages/Geometry3D/geometry/body.py:14, in GeoBody.intersection(self, other)
12 """return the intersection between self and other"""
13 from ..calc.intersection import intersection
---> 14 return intersection(self, other)
File python3.11/site-packages/Geometry3D/calc/intersection.py:138, in intersection(a, b)
136 # convex polyhedron
137 elif isinstance(a,ConvexPolyhedron) and isinstance(b,ConvexPolyhedron):
--> 138 return inter_convexpolyhedron_convexpolyhedron(a,b)
139 elif isinstance(a, ConvexPolyhedron) and isinstance(b, HalfLine):
140 return inter_convexpolyhedron_halfline(a,b)
File python3.11/site-packages/Geometry3D/calc/intersection.py:807, in inter_convexpolyhedron_convexpolyhedron(cph1, cph2)
805 cpg_set.add(inter)
806 for cpg in cph2.convex_polygons:
--> 807 inter = inter_convexpolygon_convexPolyhedron(cph1,cpg)
808 if inter is None:
809 continue
File python3.11/site-packages/Geometry3D/calc/intersection.py:746, in inter_convexpolygon_convexPolyhedron(cph, cpg)
737 def inter_convexpolygon_convexPolyhedron(cph,cpg):
738 """Input:
739 cph: a ConvexPolyhedron
740 cpg: a ConvexPolygon
(...)
744 the intersection part of cph and cpg
745 """
--> 746 inter_p_cph = intersection(cph,cpg.plane)
747 if inter_p_cph is None:
748 return None
File python3.11/site-packages/Geometry3D/calc/intersection.py:105, in intersection(a, b)
103 return inter_plane_convexpolyhedron(a,b)
104 elif isinstance(a,ConvexPolyhedron) and isinstance(b, Plane):
--> 105 return inter_plane_convexpolyhedron(b,a)
106 elif isinstance(a, Plane) and isinstance(b, HalfLine):
107 return inter_plane_halfline(a,b)
File python3.11/site-packages/Geometry3D/calc/intersection.py:508, in inter_plane_convexpolyhedron(a, b)
506 return Segment(point_tuple[0],point_tuple[1])
507 else:
--> 508 return ConvexPolygon(point_tuple)
File python3.11/site-packages/Geometry3D/geometry/polygon.py:133, in ConvexPolygon.__init__(self, pts, reverse, check_convex)
129 self.plane = Plane(self.points[0],self.points[1],self.points[2])
131 self.center_point = self._get_center_point()
--> 133 self._check_and_sort_points()
File python3.11/site-packages/Geometry3D/geometry/polygon.py:211, in ConvexPolygon._check_and_sort_points(self)
209 for point in self.points:
210 if not point in self.plane:
--> 211 raise ValueError('Convex Check Fails Because {} Is Not On {}'.format(point,self.plane))
212 pv = point.pv() - self.center_point.pv()
213 y_coordinate = pv * v0
ValueError: Convex Check Fails Because Point(-636.2316726828756, -323.39055174300415, -4.031296527409776) Is Not On Plane(Point(-636.2978665768319, -318.69779661131014, -3.9293749129306144), Vector(0.9996419880957945, 0.01360005268929717, 0.02304200952034214))
This is with:
bbox1 = ConvexPolyhedron({Point(-638.0112640092382, -339.2830706018351, -4.539983707967987), Point(-636.0698922945523, -334.745069045331, -4.34812808219203), Point(-638.0759883109075, -334.772361827949, -4.394369120540701), Point(-636.03961227503, -339.30545799626975, -2.970108037052072), Point(-638.0457082913852, -339.33275077888777, -3.0163490754007425), Point(-638.1104325930545, -334.82204200500166, -2.870734487973457), Point(-636.005167992883, -339.2557778192171, -4.493742669619316), Point(-636.1043365766993, -334.79474922238364, -2.824493449624786)})
bbox2 = ConvexPolyhedron({Point(-638.2855200600773, -318.9122950789289, -3.982766365222638), Point(-637.8170533786531, -323.5896296800596, -2.6317697118413648), Point(-638.3208004655334, -318.94409328652847, -2.54160145408265), Point(-636.3307758549279, -318.72933893769624, -2.4881463096358347), Point(-635.7917483625915, -323.3430771236278, -4.019479478534537), Point(-636.2954954494718, -318.69754073009665, -3.9293112207758227), Point(-637.781772973197, -323.55783147246, -4.072934622981353), Point(-635.8270287680476, -323.3748753312274, -2.5783145673945493)})
I've gotten the same error with several different bounding box pairings. I'm not sure if you have any insight as to why this error is being triggered by these combinations? The ConvexPolyhedrons are being constructed in the same way (I'm building them with a point and 3 vectors), so it's odd that some are failing in this way.