www.mooseframework.org
LineSegment.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #pragma once
11 
12 // MOOSE includes
13 #include "Moose.h" // using namespace libMesh
14 #include "DataIO.h"
15 
16 #include "json.h"
17 #include "libmesh/point.h"
18 
19 // forward declarations
20 namespace libMesh
21 {
22 class Plane;
23 }
24 
30 {
31 public:
32  LineSegment() = default;
33  LineSegment(const Point & p0, const Point & p1);
34 
35  virtual ~LineSegment() = default;
36 
42  Point closest_point(const Point & p) const;
43 
49  bool closest_normal_point(const Point & p, Point & closest_p) const;
50 
54  bool contains_point(const Point & p) const;
55 
56  bool intersect(const Plane & pl, Point & intersect_p) const;
57 
58  bool intersect(const LineSegment & l1, Point & intersect_p) const;
59 
63  const Point & start() const { return _p0; }
64 
68  const Point & end() const { return _p1; }
69 
73  void setStart(const Point & p0) { _p0 = p0; }
74 
78  void setEnd(const Point & p1) { _p1 = p1; }
79 
85  void set(const Point & p0, const Point & p1);
86 
90  Real length() const { return (_p0 - _p1).norm(); }
91 
92 private:
93  bool closest_point(const Point & p, bool clamp_to_segment, Point & closest_p) const;
94 
95  Point _p0, _p1;
96 };
97 
98 void dataStore(std::ostream & stream, LineSegment & l, void * context);
99 void dataLoad(std::istream & stream, LineSegment & l, void * context);
100 
101 void to_json(nlohmann::json & json, const LineSegment & l);
void setEnd(const Point &p1)
Sets the end of the line segment.
Definition: LineSegment.h:78
const Point & end() const
Ending of the line segment.
Definition: LineSegment.h:68
void dataLoad(std::istream &stream, LineSegment &l, void *context)
Definition: LineSegment.C:243
Real length() const
Length of segment.
Definition: LineSegment.h:90
The LineSegment class is used by the LineMaterialSamplerBase class and for some ray tracing stuff...
Definition: LineSegment.h:29
void to_json(nlohmann::json &json, const LineSegment &l)
Definition: LineSegment.C:253
Point closest_point(const Point &p) const
Returns the closest point on the LineSegment to the passed in point.
Definition: LineSegment.C:45
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
LineSegment()=default
bool intersect(const Plane &pl, Point &intersect_p) const
Definition: LineSegment.C:66
void setStart(const Point &p0)
Sets the beginning of the line segment.
Definition: LineSegment.h:73
virtual ~LineSegment()=default
bool closest_normal_point(const Point &p, Point &closest_p) const
Finds the closest point on the Line determined by the Line Segments.
Definition: LineSegment.C:53
void dataStore(std::ostream &stream, LineSegment &l, void *context)
Definition: LineSegment.C:236
const Point & start() const
Beginning of the line segment.
Definition: LineSegment.h:63
bool contains_point(const Point &p) const
Determines whether a point is in a line segment or not.
Definition: LineSegment.C:59
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real