From a5d724aa2ea7b6208583fb6e698e0665a0bf4aa2 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Sat, 8 Apr 2023 15:06:21 +0200 Subject: [PATCH] Check whether points in Plane.from_points lie along a line. --- openmc/surface.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/openmc/surface.py b/openmc/surface.py index b8ea5479d..984bc7a5c 100644 --- a/openmc/surface.py +++ b/openmc/surface.py @@ -737,16 +737,25 @@ class Plane(PlaneMixin, Surface): Plane Plane that passes through the three points + Raises + ------ + ValueError + If all three points lie along a line + """ # Convert to numpy arrays - p1 = np.asarray(p1) - p2 = np.asarray(p2) - p3 = np.asarray(p3) + p1 = np.asarray(p1, dtype=float) + p2 = np.asarray(p2, dtype=float) + p3 = np.asarray(p3, dtype=float) # Find normal vector to plane by taking cross product of two vectors # connecting p1->p2 and p1->p3 n = np.cross(p2 - p1, p3 - p1) + # Check for points along a line + if np.allclose(n, 0.): + raise ValueError("All three points appear to lie along a line.") + # The equation of the plane will by n·( - p1) = 0. Determine # coefficients a, b, c, and d based on that a, b, c = n