Skip to content

Commit 0786c9f

Browse files
committed
Add intersection tools and within_segment
1 parent 5d3faac commit 0786c9f

File tree

11 files changed

+408
-48
lines changed

11 files changed

+408
-48
lines changed

Makefile.in

Lines changed: 81 additions & 5 deletions
Large diffs are not rendered by default.

include/Makefile.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,7 @@ include_HEADERS = \
752752
geom/face_tri3_subdivision.h \
753753
geom/face_tri6.h \
754754
geom/face_tri7.h \
755+
geom/intersection_tools.h \
755756
geom/node.h \
756757
geom/node_elem.h \
757758
geom/node_range.h \

include/geom/intersection_tools.h

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// The libMesh Finite Element Library.
2+
// Copyright (C) 2002-2022 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3+
4+
// This library is free software; you can redistribute it and/or
5+
// modify it under the terms of the GNU Lesser General Public
6+
// License as published by the Free Software Foundation; either
7+
// version 2.1 of the License, or (at your option) any later version.
8+
9+
// This library is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
// Lesser General Public License for more details.
13+
14+
// You should have received a copy of the GNU Lesser General Public
15+
// License along with this library; if not, write to the Free Software
16+
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17+
18+
19+
20+
#ifndef LIBMESH_INTERSECTIONTOOLS_H
21+
#define LIBMESH_INTERSECTIONTOOLS_H
22+
23+
#include "libmesh/libmesh_common.h"
24+
25+
namespace libMesh
26+
{
27+
28+
class Point;
29+
30+
namespace IntersectionTools
31+
{
32+
33+
/**
34+
* Checks whether or not a point is within a line segment
35+
* @param s1 The first point on the segment
36+
* @param s2 The second point on the segment
37+
* @param length The segment length (for optimization if it's already computed)
38+
* @param p The point
39+
* @param tol The tolerance to use
40+
* @return If point is within the segment defined by [s1, s2]
41+
*/
42+
bool within_segment(const Point & s1,
43+
const Point & s2,
44+
const Real length,
45+
const Point & p,
46+
const Real tol = TOLERANCE);
47+
48+
/**
49+
* Checks whether or not a point is within a line segment
50+
* @param s1 The first point on the segment
51+
* @param s2 The second point on the segment
52+
* @param p The point
53+
* @param tol The tolerance to use
54+
* @return If point is within the segment defined by [s1, s2]
55+
*/
56+
bool within_segment(const Point & s1,
57+
const Point & s2,
58+
const Point & p,
59+
const Real tol = TOLERANCE);
60+
61+
} // namespace IntersectionTools
62+
} // namespace libMesh
63+
64+
#endif // LIBMESH_INTERSECTIONTOOLS_H

include/include_HEADERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ include_HEADERS = \
162162
geom/face_tri3_subdivision.h \
163163
geom/face_tri6.h \
164164
geom/face_tri7.h \
165+
geom/intersection_tools.h \
165166
geom/node.h \
166167
geom/node_elem.h \
167168
geom/node_range.h \

include/libmesh/Makefile.am

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ BUILT_SOURCES = \
152152
face_tri3_subdivision.h \
153153
face_tri6.h \
154154
face_tri7.h \
155+
intersection_tools.h \
155156
node.h \
156157
node_elem.h \
157158
node_range.h \
@@ -1017,6 +1018,9 @@ face_tri6.h: $(top_srcdir)/include/geom/face_tri6.h
10171018
face_tri7.h: $(top_srcdir)/include/geom/face_tri7.h
10181019
$(AM_V_GEN)rm -f $@ && $(LN_S) -f $< $@
10191020

1021+
intersection_tools.h: $(top_srcdir)/include/geom/intersection_tools.h
1022+
$(AM_V_GEN)rm -f $@ && $(LN_S) -f $< $@
1023+
10201024
node.h: $(top_srcdir)/include/geom/node.h
10211025
$(AM_V_GEN)rm -f $@ && $(LN_S) -f $< $@
10221026

include/libmesh/Makefile.in

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -553,13 +553,14 @@ BUILT_SOURCES = auto_ptr.h default_coupling.h dirichlet_boundaries.h \
553553
face_quad4.h face_quad4_shell.h face_quad8.h \
554554
face_quad8_shell.h face_quad9.h face_tri.h face_tri3.h \
555555
face_tri3_shell.h face_tri3_subdivision.h face_tri6.h \
556-
face_tri7.h node.h node_elem.h node_range.h plane.h point.h \
557-
reference_elem.h remote_elem.h side.h sphere.h stored_range.h \
558-
surface.h abaqus_io.h boundary_info.h boundary_mesh.h \
559-
checkpoint_io.h distributed_mesh.h dyna_io.h ensight_io.h \
560-
exodusII_io.h exodusII_io_helper.h exodus_header_info.h \
561-
fro_io.h gmsh_io.h gmv_io.h gnuplot_io.h inf_elem_builder.h \
562-
matlab_io.h medit_io.h mesh.h mesh_base.h mesh_communication.h \
556+
face_tri7.h intersection_tools.h node.h node_elem.h \
557+
node_range.h plane.h point.h reference_elem.h remote_elem.h \
558+
side.h sphere.h stored_range.h surface.h abaqus_io.h \
559+
boundary_info.h boundary_mesh.h checkpoint_io.h \
560+
distributed_mesh.h dyna_io.h ensight_io.h exodusII_io.h \
561+
exodusII_io_helper.h exodus_header_info.h fro_io.h gmsh_io.h \
562+
gmv_io.h gnuplot_io.h inf_elem_builder.h matlab_io.h \
563+
medit_io.h mesh.h mesh_base.h mesh_communication.h \
563564
mesh_function.h mesh_generation.h mesh_input.h \
564565
mesh_inserter_iterator.h mesh_modification.h mesh_output.h \
565566
mesh_refinement.h mesh_serializer.h mesh_smoother.h \
@@ -1351,6 +1352,9 @@ face_tri6.h: $(top_srcdir)/include/geom/face_tri6.h
13511352
face_tri7.h: $(top_srcdir)/include/geom/face_tri7.h
13521353
$(AM_V_GEN)rm -f $@ && $(LN_S) -f $< $@
13531354

1355+
intersection_tools.h: $(top_srcdir)/include/geom/intersection_tools.h
1356+
$(AM_V_GEN)rm -f $@ && $(LN_S) -f $< $@
1357+
13541358
node.h: $(top_srcdir)/include/geom/node.h
13551359
$(AM_V_GEN)rm -f $@ && $(LN_S) -f $< $@
13561360

src/geom/intersection_tools.C

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// The libMesh Finite Element Library.
2+
// Copyright (C) 2002-2022 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3+
4+
// This library is free software; you can redistribute it and/or
5+
// modify it under the terms of the GNU Lesser General Public
6+
// License as published by the Free Software Foundation; either
7+
// version 2.1 of the License, or (at your option) any later version.
8+
9+
// This library is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
// Lesser General Public License for more details.
13+
14+
// You should have received a copy of the GNU Lesser General Public
15+
// License along with this library; if not, write to the Free Software
16+
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17+
18+
19+
20+
#include "libmesh/intersection_tools.h"
21+
22+
#include "libmesh/point.h"
23+
24+
namespace libMesh::IntersectionTools
25+
{
26+
27+
bool within_segment(const Point & s1,
28+
const Point & s2,
29+
const Real length,
30+
const Point & p,
31+
const Real tol)
32+
{
33+
libmesh_assert(!s1.absolute_fuzzy_equals(s2, tol));
34+
libmesh_assert_less(std::abs((s1 - s2).norm() - length), tol);
35+
36+
const auto diff1 = p - s1;
37+
const auto diff2 = p - s2;
38+
39+
if (diff1 * diff2 > tol * length)
40+
return false;
41+
42+
return std::abs(diff1.norm() + diff2.norm() - length) < tol * length;
43+
}
44+
45+
bool within_segment(const Point & s1,
46+
const Point & s2,
47+
const Point & p,
48+
const Real tol)
49+
{
50+
return within_segment(s1, s2, (s1 - s2).norm(), p, tol);
51+
}
52+
53+
} // namespace libMesh::IntersectionTools
54+
55+

src/libmesh_SOURCES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ libmesh_SOURCES = \
173173
src/geom/face_tri3_subdivision.C \
174174
src/geom/face_tri6.C \
175175
src/geom/face_tri7.C \
176+
src/geom/intersection_tools.C \
176177
src/geom/node.C \
177178
src/geom/node_elem.C \
178179
src/geom/plane.C \

tests/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ unit_tests_sources = \
4747
geom/edge_test.C \
4848
geom/elem_extrema_test.C \
4949
geom/elem_test.C \
50+
geom/intersection_tools_test.C \
5051
geom/node_test.C \
5152
geom/point_test.C \
5253
geom/point_test.h \

0 commit comments

Comments
 (0)