www.mooseframework.org
Public Member Functions | Private Member Functions | Private Attributes | List of all members
LineSegment Class Reference

The LineSegment class is used by the LineMaterialSamplerBase class and for some ray tracing stuff. More...

#include <LineSegment.h>

Public Member Functions

 LineSegment ()=default
 
 LineSegment (const Point &p0, const Point &p1)
 
virtual ~LineSegment ()=default
 
Point closest_point (const Point &p) const
 Returns the closest point on the LineSegment to the passed in point. More...
 
bool closest_normal_point (const Point &p, Point &closest_p) const
 Finds the closest point on the Line determined by the Line Segments. More...
 
bool contains_point (const Point &p) const
 Determines whether a point is in a line segment or not. More...
 
bool intersect (const Plane &pl, Point &intersect_p) const
 
bool intersect (const LineSegment &l1, Point &intersect_p) const
 
const Point & start () const
 Beginning of the line segment. More...
 
const Point & end () const
 Ending of the line segment. More...
 
void setStart (const Point &p0)
 Sets the beginning of the line segment. More...
 
void setEnd (const Point &p1)
 Sets the end of the line segment. More...
 
void set (const Point &p0, const Point &p1)
 Sets the points on the line segment. More...
 
Real length () const
 Length of segment. More...
 

Private Member Functions

bool closest_point (const Point &p, bool clamp_to_segment, Point &closest_p) const
 

Private Attributes

Point _p0
 
Point _p1
 

Detailed Description

The LineSegment class is used by the LineMaterialSamplerBase class and for some ray tracing stuff.

Definition at line 29 of file LineSegment.h.

Constructor & Destructor Documentation

◆ LineSegment() [1/2]

LineSegment::LineSegment ( )
default

◆ LineSegment() [2/2]

LineSegment::LineSegment ( const Point &  p0,
const Point &  p1 
)

Definition at line 17 of file LineSegment.C.

17 : _p0(p0), _p1(p1) {}

◆ ~LineSegment()

virtual LineSegment::~LineSegment ( )
virtualdefault

Member Function Documentation

◆ closest_normal_point()

bool LineSegment::closest_normal_point ( const Point &  p,
Point &  closest_p 
) const

Finds the closest point on the Line determined by the Line Segments.

Returns a boolean indicating whether that normal point is within the LineSegment or not

Definition at line 53 of file LineSegment.C.

54 {
55  return closest_point(p, false, closest_p);
56 }
Point closest_point(const Point &p) const
Returns the closest point on the LineSegment to the passed in point.
Definition: LineSegment.C:45

◆ closest_point() [1/2]

Point LineSegment::closest_point ( const Point &  p) const

Returns the closest point on the LineSegment to the passed in point.

Note that the closest point may be one of the ends of the LineSegment.

Definition at line 45 of file LineSegment.C.

Referenced by closest_normal_point(), and contains_point().

46 {
47  Point closest_p;
48  closest_point(p, true, closest_p);
49  return closest_p;
50 }
Point closest_point(const Point &p) const
Returns the closest point on the LineSegment to the passed in point.
Definition: LineSegment.C:45

◆ closest_point() [2/2]

bool LineSegment::closest_point ( const Point &  p,
bool  clamp_to_segment,
Point &  closest_p 
) const
private

Definition at line 20 of file LineSegment.C.

21 {
22  Point p0_p = p - _p0;
23  Point p0_p1 = _p1 - _p0;
24  Real p0_p1_2 = p0_p1.norm_sq();
25  Real perp = p0_p(0) * p0_p1(0) + p0_p(1) * p0_p1(1) + p0_p(2) * p0_p1(2);
26  Real t = perp / p0_p1_2;
27  bool on_segment = true;
28 
29  if (t < 0.0 || t > 1.0)
30  on_segment = false;
31 
32  if (clamp_to_segment)
33  {
34  if (t < 0.0)
35  t = 0.0;
36  else if (t > 1.0)
37  t = 1.0;
38  }
39 
40  closest_p = _p0 + p0_p1 * t;
41  return on_segment;
42 }
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

◆ contains_point()

bool LineSegment::contains_point ( const Point &  p) const

Determines whether a point is in a line segment or not.

Definition at line 59 of file LineSegment.C.

Referenced by Moose::sideIntersectedByLine().

60 {
61  Point closest_p;
62  return closest_point(p, false, closest_p) && closest_p.absolute_fuzzy_equals(p);
63 }
Point closest_point(const Point &p) const
Returns the closest point on the LineSegment to the passed in point.
Definition: LineSegment.C:45

◆ end()

const Point& LineSegment::end ( ) const
inline

Ending of the line segment.

Definition at line 68 of file LineSegment.h.

Referenced by dataStore(), IntersectionPointsAlongLine::execute(), Moose::recursivelyFindElementsIntersectedByLine(), and to_json().

68 { return _p1; }

◆ intersect() [1/2]

bool LineSegment::intersect ( const Plane &  pl,
Point &  intersect_p 
) const

There are three cases in 3D for intersection of a line and a plane Case 1: The line is parallel to the plane - No intersection Numerator = non-zero Denominator = zero

Case 2: The line is within the plane - Inf intersection Numerator = zero Denominator = zero

Case 3: The line intersects the plane at a single point Denominator = non-zero

Definition at line 66 of file LineSegment.C.

Referenced by Moose::sideIntersectedByLine().

67 {
82  Point pl0 = pl.get_planar_point();
83  RealVectorValue N = pl.unit_normal(_p0);
84  RealVectorValue I = (_p1 - _p0).unit();
85 
86  Real numerator = (pl0 - _p0) * N;
87  Real denominator = I * N;
88 
89  // The Line is parallel to the plane
90  if (std::abs(denominator) < 1.e-10)
91  {
92  // The Line is on the plane
93  if (std::abs(numerator) < 1.e-10)
94  {
95  // The solution is not unique so we'll just pick an end point for now
96  intersect_p = _p0;
97  return true;
98  }
99  return false;
100  }
101 
102  Real d = numerator / denominator;
103 
104  // Make sure we haven't moved off the line segment!
105  if (d + libMesh::TOLERANCE < 0 || d - libMesh::TOLERANCE > (_p1 - _p0).norm())
106  return false;
107 
108  intersect_p = d * I + _p0;
109 
110  return true;
111 }
ADRealEigenVector< T, D, asd > abs(const ADRealEigenVector< T, D, asd > &)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

◆ intersect() [2/2]

bool LineSegment::intersect ( const LineSegment l1,
Point &  intersect_p 
) const

First check for concurance:

| x1 y1 z1 1 | | x2 y2 z2 1 | = (x3 - x1) * [(x2-x1) x (x4-x3)] = 0 | x3 y3 z3 1 | | x4 y4 z4 1 |

Solve: x = _p0 + (_p1 - _p0)*s x = l.p0 + (l._p1 - l.p0)*t

where a = _p1 - _p0 b = l._p1 - l._p0 c = l._p0 - _p0

s = (c x b) * (a x b) / | a x b |^2

 Parameteric Equation of lines
 _p0 + t(v0) = l._p0 + u(v1)

 Case 1: Parallel Lines
         v0 x v1 == 0

 Case 1a: Collinear Lines
         v0 x v1 == 0
         (l._p0 - _p0) x (_p1 - _p0) == 0

 Case 2: Intersecting Lines
         0 <= t <= 1
         0 <= u <= 1


 Case 1: The lines do not intersect
         vleft cross vright = non-zero

 Case 2: The lines are co-linear
         vleft cross vright = zero
         vleft (Denominator) = zero

 Case 3: The line intersect at a single point
         vleft cross vright = zero
         vleft (Denominator) = non-zero

RealVectorValue v0 = _p1 - _p0; RealVectorValue v1 = l._p1 - l._p0; RealVectorValue v2 = l._p0 - _p0;

RealVectorValue vbot = v0.cross(v1); RealVectorValue vtop = v2.cross(v1);

RealVectorValue crossed = vleft.cross(vright);

Case 1: No intersection if (std::abs(vleft.cross(vright).size()) > 1.e-10) return false;

Case 2: Co-linear (just return one of the end points) if (std::abs(vleft.size()) < 1.e-10) { intersect_p = _p0; return true; }

Case 3:

TODO: We could detect whether the Line Segments actually overlap instead of whether the Lines are co-linear

Real a = vright.size()/vleft.size(); intersect_p = _p0 + a*v0; return true;

Definition at line 114 of file LineSegment.C.

115 {
137  RealVectorValue a = _p1 - _p0;
138  RealVectorValue b = l._p1 - l._p0;
139  RealVectorValue c = l._p0 - _p0;
140 
141  RealVectorValue v = a.cross(b);
142 
143  // Check for parallel lines
144  if (std::abs(v.norm()) < 1.e-10 && std::abs(c.cross(a).norm()) < 1.e-10)
145  {
146  // TODO: The lines are co-linear but more work is needed to determine and intersection point
147  // it could be the case that the line segments don't lie on the same line or overlap only
148  // a bit
149  return true;
150  }
151 
152  // Check that the lines are coplanar
153  Real concur = c * (a.cross(b));
154  if (std::abs(concur) > 1.e-10)
155  return false;
156 
157  Real s = (c.cross(b) * v) / (v * v);
158  Real t = (c.cross(a) * v) / (v * v);
159 
160  // if s and t are between 0 and 1 then the Line Segments intersect
161  // TODO: We could handle other case of clamping to the end of Line
162  // Segements if we want to here
163 
164  if (s >= 0 && s <= 1 && t >= 0 && t <= 1)
165  {
166  intersect_p = _p0 + s * a;
167  return true;
168  }
169  return false;
170 
226 }
auto norm() const -> decltype(std::norm(Real()))
ADRealEigenVector< T, D, asd > abs(const ADRealEigenVector< T, D, asd > &)
TypeVector< typename CompareTypes< Real, T2 >::supertype > cross(const TypeVector< T2 > &v) const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

◆ length()

Real LineSegment::length ( ) const
inline

Length of segment.

Definition at line 90 of file LineSegment.h.

90 { return (_p0 - _p1).norm(); }

◆ set()

void LineSegment::set ( const Point &  p0,
const Point &  p1 
)

Sets the points on the line segment.

Parameters
p0The start point of the line segment
p1The end point of the line segment

Definition at line 229 of file LineSegment.C.

Referenced by dataLoad().

230 {
231  setStart(p0);
232  setEnd(p1);
233 }
void setEnd(const Point &p1)
Sets the end of the line segment.
Definition: LineSegment.h:78
void setStart(const Point &p0)
Sets the beginning of the line segment.
Definition: LineSegment.h:73

◆ setEnd()

void LineSegment::setEnd ( const Point &  p1)
inline

Sets the end of the line segment.

Definition at line 78 of file LineSegment.h.

Referenced by set().

78 { _p1 = p1; }

◆ setStart()

void LineSegment::setStart ( const Point &  p0)
inline

Sets the beginning of the line segment.

Definition at line 73 of file LineSegment.h.

Referenced by set().

73 { _p0 = p0; }

◆ start()

const Point& LineSegment::start ( ) const
inline

Beginning of the line segment.

Definition at line 63 of file LineSegment.h.

Referenced by dataStore(), and to_json().

63 { return _p0; }

Member Data Documentation

◆ _p0

Point LineSegment::_p0
private

Definition at line 95 of file LineSegment.h.

Referenced by closest_point(), intersect(), length(), setStart(), and start().

◆ _p1

Point LineSegment::_p1
private

Definition at line 95 of file LineSegment.h.

Referenced by closest_point(), end(), intersect(), length(), and setEnd().


The documentation for this class was generated from the following files: