https://mooseframework.inl.gov
LineSegment.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
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 "DataIO.h"
14 
15 #include "json.h"
16 #include "libmesh/point.h"
17 
18 // forward declarations
19 namespace libMesh
20 {
21 class Plane;
22 }
23 
29 {
30 public:
31  LineSegment() = default;
32  LineSegment(const Point & p0, const Point & p1);
33 
34  virtual ~LineSegment() = default;
35 
41  Point closest_point(const Point & p) const;
42 
48  bool closest_normal_point(const Point & p, Point & closest_p) const;
49 
53  bool contains_point(const Point & p) const;
54 
55  bool intersect(const libMesh::Plane & pl, Point & intersect_p) const;
56 
57  bool intersect(const LineSegment & l1, Point & intersect_p) const;
58 
62  const Point & start() const { return _p0; }
63 
67  const Point & end() const { return _p1; }
68 
72  void setStart(const Point & p0) { _p0 = p0; }
73 
77  void setEnd(const Point & p1) { _p1 = p1; }
78 
84  void set(const Point & p0, const Point & p1);
85 
89  Real length() const { return (_p0 - _p1).norm(); }
90 
91 private:
92  bool closest_point(const Point & p, bool clamp_to_segment, Point & closest_p) const;
93 
94  Point _p0, _p1;
95 };
96 
97 void dataStore(std::ostream & stream, LineSegment & l, void * context);
98 void dataLoad(std::istream & stream, LineSegment & l, void * context);
99 
100 void to_json(nlohmann::json & json, const LineSegment & l);
void setEnd(const Point &p1)
Sets the end of the line segment.
Definition: LineSegment.h:77
const Point & end() const
Ending of the line segment.
Definition: LineSegment.h:67
void dataLoad(std::istream &stream, LineSegment &l, void *context)
Definition: LineSegment.C:243
Real length() const
Length of segment.
Definition: LineSegment.h:89
The LineSegment class is used by the LineMaterialSamplerBase class and for some ray tracing stuff...
Definition: LineSegment.h:28
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
void setStart(const Point &p0)
Sets the beginning of the line segment.
Definition: LineSegment.h:72
virtual ~LineSegment()=default
bool intersect(const libMesh::Plane &pl, Point &intersect_p) const
Definition: LineSegment.C:66
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:62
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