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 "Ball.h"
14 #include "DataIO.h"
15 #include "GeometryBase.h"
16 
17 #include "json.h"
18 #include "libmesh/point.h"
19 
20 // forward declarations
21 namespace libMesh
22 {
23 class Plane;
24 }
25 
30 class LineSegment : public GeometryBase
31 {
32 public:
33  LineSegment() = default;
34  LineSegment(const Point & p0, const Point & p1);
35 
36  ~LineSegment() override = default;
37 
43  Point closest_point(const Point & p) const;
44 
50  bool closest_normal_point(const Point & p, Point & closest_p) const;
51 
55  bool contains_point(const Point & p) const;
56 
60  bool intersect(const libMesh::Plane & pl, Point & intersect_p) const;
61 
66  bool intersect(const LineSegment & l1, Point & intersect_p) const;
67 
72  bool intersect(const LineSegment & line_segment) const override;
73 
80  Ball computeBoundingBall() const override;
81 
85  const Point & start() const { return _p0; }
86 
90  const Point & end() const { return _p1; }
91 
95  void setStart(const Point & p0) { _p0 = p0; }
96 
100  void setEnd(const Point & p1) { _p1 = p1; }
101 
107  void set(const Point & p0, const Point & p1);
108 
112  Real length() const { return (_p0 - _p1).norm(); }
113 
117  Point normal() const;
118 
119 private:
120  bool closest_point(const Point & p, bool clamp_to_segment, Point & closest_p) const;
121 
122  Point _p0, _p1;
123 };
124 
125 void dataStore(std::ostream & stream, LineSegment & l, void * context);
126 void dataLoad(std::istream & stream, LineSegment & l, void * context);
127 
128 void to_json(nlohmann::json & json, const LineSegment & l);
void setEnd(const Point &p1)
Sets the end of the line segment.
Definition: LineSegment.h:100
const Point & end() const
Ending of the line segment.
Definition: LineSegment.h:90
Ball primitive: a circle in 2D or a sphere in 3D.
Definition: Ball.h:34
void dataLoad(std::istream &stream, LineSegment &l, void *context)
Definition: LineSegment.C:274
Real length() const
Length of segment.
Definition: LineSegment.h:112
The LineSegment class is used by the LineMaterialSamplerBase class and for some ray tracing stuff...
Definition: LineSegment.h:30
void to_json(nlohmann::json &json, const LineSegment &l)
Definition: LineSegment.C:284
Point closest_point(const Point &p) const
Returns the closest point on the LineSegment to the passed in point.
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
LineSegment()=default
Point normal() const
normal vector of the line segment
Definition: LineSegment.C:291
void setStart(const Point &p0)
Sets the beginning of the line segment.
Definition: LineSegment.h:95
bool intersect(const libMesh::Plane &pl, Point &intersect_p) const
Check if a line segment intersects a plane, and if so, return the intersection point.
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:57
void dataStore(std::ostream &stream, LineSegment &l, void *context)
Definition: LineSegment.C:267
Ball computeBoundingBall() const override
Compute a bounding ball for this line segment.
Definition: LineSegment.C:303
const Point & start() const
Beginning of the line segment.
Definition: LineSegment.h:85
bool contains_point(const Point &p) const
Determines whether a point is in a line segment or not.
Definition: LineSegment.C:63
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Base class for geometry primitives.
Definition: GeometryBase.h:18
~LineSegment() override=default