15#include "libmesh/plane.h"
16#include "libmesh/vector_value.h"
25 Real p0_p1_2 = p0_p1.norm_sq();
26 Real perp = p0_p(0) * p0_p1(0) + p0_p(1) * p0_p1(1) + p0_p(2) * p0_p1(2);
27 Real t = perp / p0_p1_2;
28 bool on_segment =
true;
30 if (t < 0.0 || t > 1.0)
41 closest_p =
_p0 + p0_p1 * t;
63 return closest_point(p,
false, closest_p) && closest_p.absolute_fuzzy_equals(p);
85 RealVectorValue I = (
_p1 -
_p0).unit();
87 Real numerator = (pl0 -
_p0) * N;
88 Real denominator = I * N;
91 if (std::abs(denominator) < 1.e-10)
94 if (std::abs(numerator) < 1.e-10)
103 Real d = numerator / denominator;
106 if (d + libMesh::TOLERANCE < 0 || d - libMesh::TOLERANCE > (
_p1 -
_p0).norm())
109 intersect_p = d * I +
_p0;
138 RealVectorValue a =
_p1 -
_p0;
139 RealVectorValue b = l.
_p1 - l.
_p0;
140 RealVectorValue c = l.
_p0 -
_p0;
142 RealVectorValue v = a.
cross(b);
144 const auto tol = 1.e-10;
150 if (c.cross(a).norm() >= tol)
174 Real concur = c * (a.cross(b));
175 if (std::abs(concur) > 1.e-10)
178 Real s = (c.cross(b) * v) / (v * v);
179 Real t = (c.cross(a) * v) / (v * v);
185 if (s >= 0 && s <= 1 && t >= 0 && t <= 1)
187 intersect_p =
_p0 + s * a;
290 const auto tangent =
_p1 -
_p0;
293 Point n(-tangent(1), tangent(0), 0.0);
294 const Real norm = n.norm();
296 mooseError(
"LineSegment: cannot compute the normal of a zero-length line segment.");
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)
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Ball primitive: a circle in 2D or a sphere in 3D.
The LineSegment class is used by the LineMaterialSamplerBase class and for some ray tracing stuff.
Ball computeBoundingBall() const override
Compute a bounding ball for this line segment.
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.
bool contains_point(const Point &p) const
Determines whether a point is in a line segment or not.
const Point & end() const
Ending of the line segment.
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.
Point normal() const
normal vector of the line segment
void setEnd(const Point &p1)
Sets the end of the line segment.
const Point & start() const
Beginning of the line segment.
Point closest_point(const Point &p) const
Returns the closest point on the LineSegment to the passed in point.
const Point & get_planar_point() const
virtual Point unit_normal(const Point &p) const override
TypeVector< typename CompareTypes< T, T2 >::supertype > cross(const TypeVector< T2 > &v) const