Skip to content

Commit 02e5162

Browse files
IgarizzaIAntonau
andauthored
[CORE] Fix IsInside of Truss_3D_2 (#14304)
* Add Point Projection * addin test case * adding distance check * moving the disctance * revert the positioning of the distance check to be in IsInside --------- Co-authored-by: IAntonau <ihar.antonau@tu-bs.de>
1 parent 3c5cd22 commit 02e5162

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

kratos/geometries/line_3d_2.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,12 @@ class Line3D2 : public Geometry<TPointType>
842842
PointLocalCoordinates( rResult, rPoint );
843843

844844
if ( std::abs( rResult[0] ) <= (1.0 + Tolerance) ) {
845+
// Check if point is too far away from the line, if so, return false
846+
const double distance = this->CalculateDistance(rPoint, Tolerance);
847+
const double length = Length();
848+
if (distance > std::max(Tolerance, 1e-6 * length)) {
849+
return false;
850+
}
845851
return true;
846852
}
847853

@@ -880,7 +886,6 @@ class Line3D2 : public Geometry<TPointType>
880886

881887
// Project point
882888
const double tolerance = 1e-14; // Tolerance
883-
884889
const double length = Length();
885890

886891
const double length_1 = std::sqrt( std::pow(rPoint[0] - r_first_point[0], 2)

kratos/tests/cpp_tests/geometries/test_line_3d_2.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,16 @@ namespace Testing {
5757
);
5858
}
5959

60+
/** Generates a point type sample Line3D2N
61+
* @return Pointer to a Line3D2N
62+
*/
63+
Line3D2<Point>::Pointer GenerateCornerCasePointsLine3D2() {
64+
return Kratos::make_shared<Line3D2<Point>>(
65+
Kratos::make_shared<Point>(-20.0, 0.0, 0.0),
66+
Kratos::make_shared<Point>(-20.0, 5.0, 0.0)
67+
);
68+
}
69+
6070
/** Generates a point type sample Line3D2N.
6171
* @return Pointer to a Line3D2N
6272
*/
@@ -121,6 +131,11 @@ namespace Testing {
121131
KRATOS_EXPECT_FALSE(p_geom->IsInside(PointOutside, LocalCoords, EPSILON));
122132
KRATOS_EXPECT_TRUE(p_geom->IsInside(PointInVertex, LocalCoords, EPSILON));
123133
KRATOS_EXPECT_TRUE(p_geom->IsInside(PointInEdge, LocalCoords, EPSILON));
134+
135+
// testing Corner Case
136+
Geometry<Point>::Pointer p_geom2 = GenerateCornerCasePointsLine3D2();
137+
Point PointOutside2(-16.0, 2.5, 0.0);
138+
KRATOS_EXPECT_FALSE(p_geom2->IsInside(PointOutside2, LocalCoords, EPSILON));
124139
}
125140

126141
/** Checks the point local coordinates for a given point respect to the

0 commit comments

Comments
 (0)