From fe2ace7321690b44b4693a6c61a5ccd74056b812 Mon Sep 17 00:00:00 2001 From: Christophe Bourcier Date: Wed, 21 Feb 2024 10:57:22 +0100 Subject: [PATCH] WIP: avoid division by zero if 3 points are aligned In case of polyhedron similar to a box with 2 coplanar faces (i.e. a box's face split by an edge on its middle) TODO: add a test --- src/INTERP_KERNEL/InterpolationUtils.hxx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/INTERP_KERNEL/InterpolationUtils.hxx b/src/INTERP_KERNEL/InterpolationUtils.hxx index 901b27a23..ce8ae5055 100644 --- a/src/INTERP_KERNEL/InterpolationUtils.hxx +++ b/src/INTERP_KERNEL/InterpolationUtils.hxx @@ -1306,7 +1306,10 @@ namespace INTERP_KERNEL double XA_cross_XB[3] = {XA[1]*XB[2]-XA[2]*XB[1], XA[2]*XB[0]-XA[0]*XB[2], XA[0]*XB[1]-XA[1]*XB[0]}; // norm is equal to double the area of the triangle double norm = std::sqrt(XA_cross_XB[0]*XA_cross_XB[0]+XA_cross_XB[1]*XA_cross_XB[1]+XA_cross_XB[2]*XA_cross_XB[2]); - + // if 3 points A B X are aligned, norm is 0 + // return 0 to avoid division by 0 + if (norm::epsilon()) + return 0; return ( XA_cross_XB[0]*XC[0]+ XA_cross_XB[1]*XC[1] + XA_cross_XB[2]*XC[2] ) / norm; } -- 2.39.2