https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
21namespace libMesh
22{
23class Plane;
24}
25
31{
32public:
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
119private:
120 bool closest_point(const Point & p, bool clamp_to_segment, Point & closest_p) const;
121
122 Point _p0, _p1;
123};
124
125void dataStore(std::ostream & stream, LineSegment & l, void * context);
126void dataLoad(std::istream & stream, LineSegment & l, void * context);
127
128void to_json(nlohmann::json & json, const LineSegment & l);
void dataLoad(std::istream &stream, LineSegment &l, void *context)
void to_json(nlohmann::json &json, const LineSegment &l)
void dataStore(std::ostream &stream, LineSegment &l, void *context)
Ball primitive: a circle in 2D or a sphere in 3D.
Definition Ball.h:35
Base class for geometry primitives.
The LineSegment class is used by the LineMaterialSamplerBase class and for some ray tracing stuff.
Definition LineSegment.h:31
LineSegment()=default
Ball computeBoundingBall() const override
Compute a bounding ball for this line segment.
bool intersect(const LineSegment &l1, Point &intersect_p) const
Check if a line segment intersects another line segment, and if so, return the intersection point.
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.
Definition LineSegment.C:70
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
Real length() const
Length of segment.
bool contains_point(const Point &p) const
Determines whether a point is in a line segment or not.
Definition LineSegment.C:63
const Point & end() const
Ending of the line segment.
Definition LineSegment.h:90
void set(const Point &p0, const Point &p1)
Sets the points on the line segment.
void setStart(const Point &p0)
Sets the beginning of the line segment.
Definition LineSegment.h:95
Point normal() const
normal vector of the line segment
void setEnd(const Point &p1)
Sets the end of the line segment.
~LineSegment() override=default
const Point & start() const
Beginning of the line segment.
Definition LineSegment.h:85
Point closest_point(const Point &p) const
Returns the closest point on the LineSegment to the passed in point.
Definition LineSegment.C:49
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...