From 95f9e1b3cdcd2c61522e8a1d7a326bb05b9a6a00 Mon Sep 17 00:00:00 2001 From: WirajanDASILVA Date: Wed, 29 Nov 2023 11:40:34 -0300 Subject: [PATCH 1/7] add fix --- volmdlr/utils/intersections.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/volmdlr/utils/intersections.py b/volmdlr/utils/intersections.py index 406cd4f04..90f780319 100644 --- a/volmdlr/utils/intersections.py +++ b/volmdlr/utils/intersections.py @@ -359,20 +359,21 @@ def get_plane_line_intersections(plane_frame, line, abs_tol: float = 1e-6): return [line.point1 + intersection_abscissea * u_vector] -def get_two_planes_intersections(plane1_frame, plane2_frame): +def get_two_planes_intersections(plane1_frame, plane2_frame, abs_tol=1e-8): """ Calculates the intersections between two planes, given their frames. :param plane1_frame: Plane's 1 frame. :param plane2_frame: Plane's 2 frame. + :param abs_tol: tolerance. :return: A list containing two points that define an infinite line if there is any intersections, or an empty list if the planes are parallel. """ - if plane1_frame.w.is_colinear_to(plane2_frame.w): + if plane1_frame.w.is_colinear_to(plane2_frame.w, abs_tol): return [] line_direction = plane1_frame.w.cross(plane2_frame.w) - if line_direction.norm() < 1e-6: + if line_direction.norm() < abs_tol: return None a1, b1, c1, d1 = get_plane_equation_coefficients(plane1_frame) From 62eca89dd01acc4a700d4759cd9e510d2d8d513c Mon Sep 17 00:00:00 2001 From: WirajanDASILVA Date: Wed, 29 Nov 2023 11:42:16 -0300 Subject: [PATCH 2/7] fix unittest --- volmdlr/utils/intersections.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/volmdlr/utils/intersections.py b/volmdlr/utils/intersections.py index 90f780319..c918d2679 100644 --- a/volmdlr/utils/intersections.py +++ b/volmdlr/utils/intersections.py @@ -81,7 +81,7 @@ def conic3d_line_intersections(conic3d, line3d, abs_tol: float = 1e-6): intersections.append(conic3d.frame.local_to_global_coordinates(inter)) return intersections - if line3d.point1.z == line3d.point2.z == conic3d.frame.origin.z: + if abs(line3d.point1.z - line3d.point2.z) <= abs_tol and abs(line3d.point1.z - conic3d.frame.origin.z) <= abs_tol: conic2d = conic3d.self_2d line2d = line3d.to_2d(conic3d.frame.origin, conic3d.frame.u, conic3d.frame.v) intersections_2d = conic2d.line_intersections(line2d) From 5f7f6d135d7ba0a4ef054ffd232d196207617542 Mon Sep 17 00:00:00 2001 From: WirajanDASILVA Date: Wed, 29 Nov 2023 12:38:11 -0300 Subject: [PATCH 3/7] add unittest --- .../test_planef_inters291123.json | 217 ++++++++++++++++++ tests/faces/test_planeface3d.py | 8 + 2 files changed, 225 insertions(+) create mode 100644 tests/faces/objects_planeface_tests/test_planef_inters291123.json diff --git a/tests/faces/objects_planeface_tests/test_planef_inters291123.json b/tests/faces/objects_planeface_tests/test_planef_inters291123.json new file mode 100644 index 000000000..f975bef4a --- /dev/null +++ b/tests/faces/objects_planeface_tests/test_planef_inters291123.json @@ -0,0 +1,217 @@ +{ + "object_class": "volmdlr.core.VolumeModel", + "name": "", + "primitives": [ + { + "object_class": "volmdlr.faces.PlaneFace3D", + "name": "", + "surface3d": { + "object_class": "volmdlr.surfaces.Plane3D", + "name": "", + "frame": { + "object_class": "volmdlr.Frame3D", + "name": "", + "origin": { + "object_class": "volmdlr.Point3D", + "x": -0.006066296085499995, + "y": -0.00046706095649999557, + "z": 0.07196336225667499 + }, + "u": { + "object_class": "volmdlr.Vector3D", + "x": 1.0, + "y": 0.0, + "z": 0.0 + }, + "v": { + "object_class": "volmdlr.Vector3D", + "x": 0.0, + "y": 1.0, + "z": 0.0 + }, + "w": { + "object_class": "volmdlr.Vector3D", + "x": 0.0, + "y": 0.0, + "z": 1.0 + } + } + }, + "surface2d": { + "object_class": "volmdlr.surfaces.Surface2D", + "name": "name", + "outer_contour": { + "object_class": "volmdlr.wires.Contour2D", + "name": "", + "primitives": [ + { + "object_class": "volmdlr.edges.LineSegment2D", + "name": "", + "start": { + "object_class": "volmdlr.Point2D", + "x": -0.08231778158047501, + "y": -0.063992739412875 + }, + "end": { + "object_class": "volmdlr.Point2D", + "x": 0.08231778158047501, + "y": -0.063992739412875 + } + }, + { + "object_class": "volmdlr.edges.LineSegment2D", + "name": "", + "start": { + "object_class": "volmdlr.Point2D", + "x": 0.08231778158047501, + "y": -0.063992739412875 + }, + "end": { + "object_class": "volmdlr.Point2D", + "x": 0.08231778158047501, + "y": 0.063992739412875 + } + }, + { + "object_class": "volmdlr.edges.LineSegment2D", + "name": "", + "start": { + "object_class": "volmdlr.Point2D", + "x": 0.08231778158047501, + "y": 0.063992739412875 + }, + "end": { + "object_class": "volmdlr.Point2D", + "x": -0.08231778158047501, + "y": 0.063992739412875 + } + }, + { + "object_class": "volmdlr.edges.LineSegment2D", + "name": "", + "start": { + "object_class": "volmdlr.Point2D", + "x": -0.08231778158047501, + "y": 0.063992739412875 + }, + "end": { + "object_class": "volmdlr.Point2D", + "x": -0.08231778158047501, + "y": -0.063992739412875 + } + } + ] + }, + "inner_contours": [] + }, + "color": null, + "alpha": 1.0 + }, + { + "object_class": "volmdlr.faces.PlaneFace3D", + "name": "", + "surface3d": { + "object_class": "volmdlr.surfaces.Plane3D", + "name": "", + "frame": { + "object_class": "volmdlr.Frame3D", + "name": "", + "origin": { + "object_class": "volmdlr.Point3D", + "x": 0.033302871957624644, + "y": 0.02975212779047777, + "z": 0.07196864601279654 + }, + "u": { + "object_class": "volmdlr.Vector3D", + "x": 0.02131057692797271, + "y": -0.9997727924804454, + "z": -0.00047193945516308105 + }, + "v": { + "object_class": "volmdlr.Vector3D", + "x": 0.9997728099006772, + "y": 0.021310777214183903, + "z": -0.00042350659024547194 + }, + "w": { + "object_class": "volmdlr.Vector3D", + "x": -0.00043346776295114854, + "y": 0.0004628070654204609, + "z": -0.9999997989576392 + } + } + }, + "surface2d": { + "object_class": "volmdlr.surfaces.Surface2D", + "name": "copy_name", + "outer_contour": { + "object_class": "volmdlr.wires.Contour2D", + "name": "", + "primitives": [ + { + "object_class": "volmdlr.edges.LineSegment2D", + "name": "", + "start": { + "object_class": "volmdlr.Point2D", + "x": 0.022, + "y": 0.000499999999999997 + }, + "end": { + "object_class": "volmdlr.Point2D", + "x": 0.0, + "y": 0.000499999999999997 + } + }, + { + "object_class": "volmdlr.edges.LineSegment2D", + "name": "", + "start": { + "object_class": "volmdlr.Point2D", + "x": 0.0, + "y": 0.000499999999999997 + }, + "end": { + "object_class": "volmdlr.Point2D", + "x": 0.0, + "y": 0.0040999999999999995 + } + }, + { + "object_class": "volmdlr.edges.LineSegment2D", + "name": "", + "start": { + "object_class": "volmdlr.Point2D", + "x": 0.0, + "y": 0.0040999999999999995 + }, + "end": { + "object_class": "volmdlr.Point2D", + "x": 0.022, + "y": 0.0040999999999999995 + } + }, + { + "object_class": "volmdlr.edges.LineSegment2D", + "name": "", + "start": { + "object_class": "volmdlr.Point2D", + "x": 0.022, + "y": 0.0040999999999999995 + }, + "end": { + "object_class": "volmdlr.Point2D", + "x": 0.022, + "y": 0.000499999999999997 + } + } + ] + }, + "inner_contours": [] + }, + "color": null, + "alpha": 1.0 + } + ], + "_references": {} +} diff --git a/tests/faces/test_planeface3d.py b/tests/faces/test_planeface3d.py index 528edddee..c371b7150 100644 --- a/tests/faces/test_planeface3d.py +++ b/tests/faces/test_planeface3d.py @@ -35,6 +35,14 @@ def test_plane_face_intersection(self): self.assertEqual(1, len(face_intersections)) self.assertAlmostEqual(0.003600000000881293, face_intersections[0].length()) + face1, face2 = faces.PlaneFace3D.load_from_file( + os.path.join(folder, 'test_planef_inters291123.json')).primitives + face_intersections = face1.face_intersections(face2) + line_seg = edges.LineSegment3D( + volmdlr.Point3D(0.034031786272172244, 0.019018077708099396, 0.07196336225667499), + volmdlr.Point3D(0.03756212352555941, 0.022324611455208112, 0.07196336225667499) + ) + self.assertTrue(face_intersections[0].primitives[0], line_seg) def test_face_inside(self): face2 = self.face.frame_mapping(volmdlr.Frame3D(volmdlr.Point3D(0, 0, 0), volmdlr.Vector3D(0.5, 0, 0), From e38ce9f656c3b2429ba47ead287ae0e009beec7e Mon Sep 17 00:00:00 2001 From: WirajanDASILVA Date: Wed, 29 Nov 2023 12:43:15 -0300 Subject: [PATCH 4/7] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7066390ed..0c6d02dda 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -74,6 +74,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 #### surfaces.py - SphericalSurface3D: use circle 3d instead of polygon3D for plotting. +- add bigger precision to plane-plane intersections. #### utils - common_operations separate_points_by_closeness: consider more than two cluster groups. From df41b5b335fa3f226913a2fd76c00b1b678ce985 Mon Sep 17 00:00:00 2001 From: WirajanDASILVA Date: Wed, 29 Nov 2023 13:53:49 -0300 Subject: [PATCH 5/7] simplify --- volmdlr/utils/intersections.py | 37 +++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/volmdlr/utils/intersections.py b/volmdlr/utils/intersections.py index c918d2679..f3a52d2c2 100644 --- a/volmdlr/utils/intersections.py +++ b/volmdlr/utils/intersections.py @@ -359,23 +359,11 @@ def get_plane_line_intersections(plane_frame, line, abs_tol: float = 1e-6): return [line.point1 + intersection_abscissea * u_vector] -def get_two_planes_intersections(plane1_frame, plane2_frame, abs_tol=1e-8): +def _helper_two_plane_intersections(plane1_frame, plane2_frame): """ - Calculates the intersections between two planes, given their frames. + Helper funtion to get point 1 on two plane intersections. - :param plane1_frame: Plane's 1 frame. - :param plane2_frame: Plane's 2 frame. - :param abs_tol: tolerance. - :return: A list containing two points that define an infinite line if there is any intersections, - or an empty list if the planes are parallel. """ - if plane1_frame.w.is_colinear_to(plane2_frame.w, abs_tol): - return [] - line_direction = plane1_frame.w.cross(plane2_frame.w) - - if line_direction.norm() < abs_tol: - return None - a1, b1, c1, d1 = get_plane_equation_coefficients(plane1_frame) a2, b2, c2, d2 = get_plane_equation_coefficients(plane2_frame) if not math.isclose(a1 * b2 - a2 * b1, 0.0, abs_tol=1e-10): @@ -392,4 +380,25 @@ def get_two_planes_intersections(plane1_frame, plane2_frame, abs_tol=1e-8): point1 = volmdlr.Point3D(0, y0, z0) else: raise NotImplementedError + return point1 + + +def get_two_planes_intersections(plane1_frame, plane2_frame, abs_tol=1e-8): + """ + Calculates the intersections between two planes, given their frames. + + :param plane1_frame: Plane's 1 frame. + :param plane2_frame: Plane's 2 frame. + :param abs_tol: tolerance. + :return: A list containing two points that define an infinite line if there is any intersections, + or an empty list if the planes are parallel. + """ + if plane1_frame.w.is_colinear_to(plane2_frame.w, abs_tol): + return [] + line_direction = plane1_frame.w.cross(plane2_frame.w) + + if line_direction.norm() < abs_tol: + return None + + point1 = _helper_two_plane_intersections(plane1_frame, plane2_frame) return [point1, point1 + line_direction] From 2adaa9c46cfc763603eb124e96e2c3ee1b33e9de Mon Sep 17 00:00:00 2001 From: WirajanDASILVA Date: Wed, 29 Nov 2023 14:52:42 -0300 Subject: [PATCH 6/7] fix pylint --- volmdlr/utils/intersections.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/volmdlr/utils/intersections.py b/volmdlr/utils/intersections.py index f3a52d2c2..55f8290bd 100644 --- a/volmdlr/utils/intersections.py +++ b/volmdlr/utils/intersections.py @@ -361,7 +361,7 @@ def get_plane_line_intersections(plane_frame, line, abs_tol: float = 1e-6): def _helper_two_plane_intersections(plane1_frame, plane2_frame): """ - Helper funtion to get point 1 on two plane intersections. + Helper function to get point 1 on two plane intersections. """ a1, b1, c1, d1 = get_plane_equation_coefficients(plane1_frame) From 93760f92eff80088cd8152695865e1a6a63770fe Mon Sep 17 00:00:00 2001 From: WirajanDASILVA Date: Thu, 30 Nov 2023 11:48:17 -0300 Subject: [PATCH 7/7] add fix to pydocstyle --- volmdlr/faces.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/volmdlr/faces.py b/volmdlr/faces.py index a97bf36e6..c28630db2 100644 --- a/volmdlr/faces.py +++ b/volmdlr/faces.py @@ -2878,6 +2878,10 @@ def __init__(self, @property def bounding_box(self): + """ + Gets the extrusion face bounding box. + + """ if not self._bbox: self._bbox = self.get_bounding_box() return self._bbox