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 (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...
 
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 33 of file LineSegment.h.

Constructor & Destructor Documentation

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

Definition at line 20 of file LineSegment.C.

20 : _p0(p0), _p1(p1) {}
virtual LineSegment::~LineSegment ( )
virtualdefault

Member Function Documentation

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 56 of file LineSegment.C.

57 {
58  return closest_point(p, false, closest_p);
59 }
Point closest_point(const Point &p) const
Returns the closest point on the LineSegment to the passed in point.
Definition: LineSegment.C:48
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 48 of file LineSegment.C.

Referenced by closest_normal_point(), and contains_point().

49 {
50  Point closest_p;
51  closest_point(p, true, closest_p);
52  return closest_p;
53 }
Point closest_point(const Point &p) const
Returns the closest point on the LineSegment to the passed in point.
Definition: LineSegment.C:48
bool LineSegment::closest_point ( const Point &  p,
bool  clamp_to_segment,
Point &  closest_p 
) const
private

Definition at line 23 of file LineSegment.C.

24 {
25  Point p0_p = p - _p0;
26  Point p0_p1 = _p1 - _p0;
27  Real p0_p1_2 = p0_p1.norm_sq();
28  Real perp = p0_p(0) * p0_p1(0) + p0_p(1) * p0_p1(1) + p0_p(2) * p0_p1(2);
29  Real t = perp / p0_p1_2;
30  bool on_segment = true;
31 
32  if (t < 0.0 || t > 1.0)
33  on_segment = false;
34 
35  if (clamp_to_segment)
36  {
37  if (t < 0.0)
38  t = 0.0;
39  else if (t > 1.0)
40  t = 1.0;
41  }
42 
43  closest_p = _p0 + p0_p1 * t;
44  return on_segment;
45 }
bool LineSegment::contains_point ( const Point &  p) const

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

Definition at line 62 of file LineSegment.C.

Referenced by Moose::sideIntersectedByLine().

63 {
64  Point closest_p;
65  return closest_point(p, false, closest_p) && closest_p.absolute_fuzzy_equals(p);
66 }
Point closest_point(const Point &p) const
Returns the closest point on the LineSegment to the passed in point.
Definition: LineSegment.C:48
const Point& LineSegment::end ( ) const
inline

Ending of the line segment.

Definition at line 71 of file LineSegment.h.

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

71 { return _p1; }
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 69 of file LineSegment.C.

Referenced by Moose::sideIntersectedByLine().

70 {
85  Point pl0 = pl.get_planar_point();
86  RealVectorValue N = pl.unit_normal(_p0);
87  RealVectorValue I = (_p1 - _p0).unit();
88 
89  Real numerator = (pl0 - _p0) * N;
90  Real denominator = I * N;
91 
92  // The Line is parallel to the plane
93  if (std::abs(denominator) < 1.e-10)
94  {
95  // The Line is on the plane
96  if (std::abs(numerator) < 1.e-10)
97  {
98  // The solution is not unique so we'll just pick an end point for now
99  intersect_p = _p0;
100  return true;
101  }
102  return false;
103  }
104 
105  Real d = numerator / denominator;
106 
107  // Make sure we haven't moved off the line segment!
108  if (d + libMesh::TOLERANCE < 0 || d - libMesh::TOLERANCE > (_p1 - _p0).norm())
109  return false;
110 
111  intersect_p = d * I + _p0;
112 
113  return true;
114 }
VectorValue< Real > RealVectorValue
Definition: Assembly.h:40
PetscInt N
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 117 of file LineSegment.C.

118 {
140  RealVectorValue a = _p1 - _p0;
141  RealVectorValue b = l._p1 - l._p0;
142  RealVectorValue c = l._p0 - _p0;
143 
144  RealVectorValue v = a.cross(b);
145 
146  // Check for parallel lines
147  if (std::abs(v.norm()) < 1.e-10 && std::abs(c.cross(a).norm()) < 1.e-10)
148  {
149  // TODO: The lines are co-linear but more work is needed to determine and intersection point
150  // it could be the case that the line segments don't lie on the same line or overlap only
151  // a bit
152  return true;
153  }
154 
155  // Check that the lines are coplanar
156  Real concur = c * (a.cross(b));
157  if (std::abs(concur) > 1.e-10)
158  return false;
159 
160  Real s = (c.cross(b) * v) / (v * v);
161  Real t = (c.cross(a) * v) / (v * v);
162 
163  // if s and t are between 0 and 1 then the Line Segments intersect
164  // TODO: We could handle other case of clamping to the end of Line
165  // Segements if we want to here
166 
167  if (s >= 0 && s <= 1 && t >= 0 && t <= 1)
168  {
169  intersect_p = _p0 + s * a;
170  return true;
171  }
172  return false;
173 
229 }
VectorValue< Real > RealVectorValue
Definition: Assembly.h:40
Real LineSegment::length ( ) const
inline

Length of segment.

Definition at line 76 of file LineSegment.h.

76 { return (_p0 - _p1).norm(); }
const Point& LineSegment::start ( ) const
inline

Beginning of the line segment.

Definition at line 66 of file LineSegment.h.

66 { return _p0; }

Member Data Documentation

Point LineSegment::_p0
private

Definition at line 81 of file LineSegment.h.

Referenced by closest_point(), and intersect().

Point LineSegment::_p1
private

Definition at line 81 of file LineSegment.h.

Referenced by closest_point(), and intersect().


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