diff --git a/kratos/geometries/line_3d_2.h b/kratos/geometries/line_3d_2.h index f1d87039bd29..e865d66f875c 100644 --- a/kratos/geometries/line_3d_2.h +++ b/kratos/geometries/line_3d_2.h @@ -842,6 +842,12 @@ class Line3D2 : public Geometry PointLocalCoordinates( rResult, rPoint ); if ( std::abs( rResult[0] ) <= (1.0 + Tolerance) ) { + // Check if point is too far away from the line, if so, return false + const double distance = this->CalculateDistance(rPoint, Tolerance); + const double length = Length(); + if (distance > std::max(Tolerance, 1e-6 * length)) { + return false; + } return true; } @@ -880,7 +886,6 @@ class Line3D2 : public Geometry // Project point const double tolerance = 1e-14; // Tolerance - const double length = Length(); const double length_1 = std::sqrt( std::pow(rPoint[0] - r_first_point[0], 2) diff --git a/kratos/tests/cpp_tests/geometries/test_line_3d_2.cpp b/kratos/tests/cpp_tests/geometries/test_line_3d_2.cpp index 3e9b7b27226a..0533c697ee2e 100644 --- a/kratos/tests/cpp_tests/geometries/test_line_3d_2.cpp +++ b/kratos/tests/cpp_tests/geometries/test_line_3d_2.cpp @@ -57,6 +57,16 @@ namespace Testing { ); } + /** Generates a point type sample Line3D2N + * @return Pointer to a Line3D2N + */ + Line3D2::Pointer GenerateCornerCasePointsLine3D2() { + return Kratos::make_shared>( + Kratos::make_shared(-20.0, 0.0, 0.0), + Kratos::make_shared(-20.0, 5.0, 0.0) + ); + } + /** Generates a point type sample Line3D2N. * @return Pointer to a Line3D2N */ @@ -121,6 +131,11 @@ namespace Testing { KRATOS_EXPECT_FALSE(p_geom->IsInside(PointOutside, LocalCoords, EPSILON)); KRATOS_EXPECT_TRUE(p_geom->IsInside(PointInVertex, LocalCoords, EPSILON)); KRATOS_EXPECT_TRUE(p_geom->IsInside(PointInEdge, LocalCoords, EPSILON)); + + // testing Corner Case + Geometry::Pointer p_geom2 = GenerateCornerCasePointsLine3D2(); + Point PointOutside2(-16.0, 2.5, 0.0); + KRATOS_EXPECT_FALSE(p_geom2->IsInside(PointOutside2, LocalCoords, EPSILON)); } /** Checks the point local coordinates for a given point respect to the