libMesh
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
libMesh::LineConstraint Class Reference

Represents a line constraint defined by a base point and direction vector. More...

#include <variational_smoother_constraint.h>

Public Member Functions

 LineConstraint ()=default
 
 LineConstraint (const Point &point, const Point &direction, const Real &tol=TOLERANCE *TOLERANCE)
 Constructor.
 
bool operator< (const LineConstraint &other) const
 Comparison operator for ordering LineConstraint objects.
 
bool operator== (const LineConstraint &other) const
 Equality operator.
 
bool contains_point (const PointConstraint &p) const
 Query whether a point lies on the line.
 
bool is_parallel (const LineConstraint &l) const
 Query whether a line is parallel to this line.
 
bool is_parallel (const PlaneConstraint &p) const
 Query whether a plane is parallel to this line.
 
ConstraintVariant intersect (const ConstraintVariant &other) const
 Computes the intersection of this line with another constraint.
 
const Point & point () const
 Const getter for the _point attribute.
 
const Point & direction () const
 Const getter for the _direction attribute.
 
const Real & tol () const
 Const getter for the _tol attribute.
 

Private Attributes

Point _point
 A point on the constraining line.
 
Point _direction
 Direction of the constraining line.
 
Real _tol
 Tolerance to use for numerical comparisons.
 

Detailed Description

Represents a line constraint defined by a base point and direction vector.

Definition at line 123 of file variational_smoother_constraint.h.

Constructor & Destructor Documentation

◆ LineConstraint() [1/2]

libMesh::LineConstraint::LineConstraint ( )
default

◆ LineConstraint() [2/2]

libMesh::LineConstraint::LineConstraint ( const Point &  point,
const Point &  direction,
const Real &  tol = TOLERANCE * TOLERANCE 
)

Constructor.

Parameters
pointA point on the constraining line.
directionthe unit direction of the constraining line.
tolThe tolerance to use for numerical comparisons.

Definition at line 80 of file variational_smoother_constraint.C.

82{
83 libmesh_assert_msg(_direction.norm() >= _tol,
84 "Can't define a line with zero magnitude direction vector.");
85}
const Point & direction() const
Const getter for the _direction attribute.
const Real & tol() const
Const getter for the _tol attribute.
const Point & point() const
Const getter for the _point attribute.
Point _direction
Direction of the constraining line.
Real _tol
Tolerance to use for numerical comparisons.
Point _point
A point on the constraining line.
auto norm() const

References _direction, _tol, and libMesh::TypeVector< T >::norm().

Member Function Documentation

◆ contains_point()

bool libMesh::LineConstraint::contains_point ( const PointConstraint &  p) const

Query whether a point lies on the line.

Parameters
pThe point in question
Returns
bool indicating whether p lies on the line.

Definition at line 104 of file variational_smoother_constraint.C.

105{
106 // If the point lies on the line, then the vector p - point is parallel to the
107 // line In that case, the cross product of p - point with the line's direction
108 // will be zero.
109 return _direction.cross(p.point() - _point).norm() < _tol;
110}
TypeVector< typename CompareTypes< T, T2 >::supertype > cross(const TypeVector< T2 > &v) const

References _direction, _point, _tol, libMesh::TypeVector< T >::cross(), and libMesh::PointConstraint::point().

Referenced by intersect(), and operator==().

◆ direction()

const Point & libMesh::LineConstraint::direction ( ) const
inline

Const getter for the _direction attribute.

Definition at line 194 of file variational_smoother_constraint.h.

194{ return _direction; }

References _direction.

Referenced by libMesh::PlaneConstraint::contains_line(), is_parallel(), operator<(), and operator==().

◆ intersect()

ConstraintVariant libMesh::LineConstraint::intersect ( const ConstraintVariant &  other) const

Computes the intersection of this line with another constraint.

Handles intersection with LineConstraint, PlaneConstraint, or PointConstraint.

Parameters
otherThe constraint to intersect with.
Returns
The most specific ConstraintVariant that satisfies both constraints. constraints. If no intersection exists, return an InvalidConstraint.

Definition at line 122 of file variational_smoother_constraint.C.

123{
124 // using visit to resolve the variant to its actual type
125 return std::visit(
126 [&](auto && o) -> ConstraintVariant {
127 // Use std::decay_t to strip references/const/volatile from o's type,
128 // so we can match the actual stored variant type in std::is_same_v.
129 using T = std::decay_t<decltype(o)>;
130 if constexpr (std::is_same_v<T, LineConstraint>)
131 {
132 if (*this == o)
133 return *this;
134
135 if (this->is_parallel(o))
136 // Lines are parallel and do not intersect
137 return InvalidConstraint();
138
139 // Solve for t in the equation p1 + t·d1 = p2 + s·d2
140 // The shortest vector between skew lines lies along the normal vector
141 // (d1 × d2). Projecting the vector (p2 - p1) onto this normal gives a
142 // scalar proportional to the distance. This is equivalent to solving:
143 // ((p2 - p1) × d2) · (d1 × d2) = t · |d1 × d2|²
144 // ⇒ t = ((delta × d2) · (d1 × d2)) / |d1 × d2|²
145
146 const Point delta = o.point() - _point;
147 const Point cross_d1_d2 = _direction.cross(o.direction());
148 const Real cross_dot = (delta.cross(o.direction())) * cross_d1_d2;
149 const Real denom = cross_d1_d2.norm_sq();
150
151 const Real t = cross_dot / denom;
152 const Point intersection = _point + t * _direction;
153
154 // Verify that intersection lies on both lines
155 if (o.direction().cross(intersection - o.point()).norm() > _tol)
156 // Lines do not intersect at a single point
157 return InvalidConstraint();
158
159 return PointConstraint{intersection};
160 }
161
162 else if constexpr (std::is_same_v<T, PlaneConstraint>)
163 return o.intersect(*this);
164
165 else if constexpr (std::is_same_v<T, PointConstraint>)
166 {
167 if (!this->contains_point(o))
168 // Point is not on the line
169 return InvalidConstraint();
170
171 return o;
172 }
173
174 else
175 libmesh_error_msg("Unsupported constraint type in Line::intersect.");
176 },
177 other);
178}
bool contains_point(const PointConstraint &p) const
Query whether a point lies on the line.
bool is_parallel(const LineConstraint &l) const
Query whether a line is parallel to this line.
LIBMESH_DEVICE_INLINE auto norm(const T &a)
std::variant< PointConstraint, LineConstraint, PlaneConstraint, InvalidConstraint > ConstraintVariant
Type used to store a constraint that may be a PlaneConstraint, LineConstraint, or PointConstraint.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

References _direction, _point, _tol, contains_point(), libMesh::TypeVector< T >::cross(), is_parallel(), libMesh::TypeVector< T >::norm_sq(), and libMesh::Real.

◆ is_parallel() [1/2]

bool libMesh::LineConstraint::is_parallel ( const LineConstraint &  l) const

Query whether a line is parallel to this line.

Parameters
lThe line in question
Returns
bool indicating whether l is parallel to this line.

Definition at line 112 of file variational_smoother_constraint.C.

113{
114 return _direction.absolute_fuzzy_equals(l.direction(), _tol);
115}
bool absolute_fuzzy_equals(const TypeVector< T > &rhs, Real tol=TOLERANCE) const

References _direction, _tol, libMesh::TypeVector< T >::absolute_fuzzy_equals(), and direction().

Referenced by intersect(), libMesh::PlaneConstraint::is_parallel(), and MeshSmootherTest::testConstraintLinePlane().

◆ is_parallel() [2/2]

bool libMesh::LineConstraint::is_parallel ( const PlaneConstraint &  p) const

Query whether a plane is parallel to this line.

Parameters
pThe plane in question
Returns
bool indicating whether p is parallel to this line.

Definition at line 117 of file variational_smoother_constraint.C.

118{
119 return std::abs(_direction * p.normal()) < _tol;
120}

References _direction, _tol, and libMesh::PlaneConstraint::normal().

◆ operator<()

bool libMesh::LineConstraint::operator< ( const LineConstraint &  other) const

Comparison operator for ordering LineConstraint objects.

The comparison is primarily based on the direction vector. If the direction vectors are equal (within tolerance), the tie is broken using the dot product of the direction with the base point.

Parameters
otherThe LineConstraint to compare with.
Returns
True if this LineConstraint is less than the other.

Definition at line 87 of file variational_smoother_constraint.C.

88{
89 if (*this == other)
90 return false;
91
92 if (!(_direction.absolute_fuzzy_equals(other.direction(), _tol)))
93 return _direction < other.direction();
94 return (_direction * _point) < (other.direction() * other.point());
95}

References _direction, _point, _tol, libMesh::TypeVector< T >::absolute_fuzzy_equals(), direction(), and point().

◆ operator==()

bool libMesh::LineConstraint::operator== ( const LineConstraint &  other) const

Equality operator.

Parameters
otherThe LineConstraint to compare with.
Returns
True if both LineConstraints represent the same line.

Definition at line 97 of file variational_smoother_constraint.C.

98{
99 if (!(_direction.absolute_fuzzy_equals(other.direction(), _tol)))
100 return false;
101 return this->contains_point(other.point());
102}

References _direction, _tol, libMesh::TypeVector< T >::absolute_fuzzy_equals(), contains_point(), direction(), and point().

◆ point()

const Point & libMesh::LineConstraint::point ( ) const
inline

Const getter for the _point attribute.

Definition at line 189 of file variational_smoother_constraint.h.

189{ return _point; }

References _point.

Referenced by libMesh::PlaneConstraint::contains_line(), operator<(), and operator==().

◆ tol()

const Real & libMesh::LineConstraint::tol ( ) const
inline

Const getter for the _tol attribute.

Definition at line 199 of file variational_smoother_constraint.h.

199{ return _tol; }

References _tol.

Member Data Documentation

◆ _direction

Point libMesh::LineConstraint::_direction
private

Direction of the constraining line.

Definition at line 211 of file variational_smoother_constraint.h.

Referenced by contains_point(), direction(), intersect(), is_parallel(), is_parallel(), LineConstraint(), operator<(), and operator==().

◆ _point

Point libMesh::LineConstraint::_point
private

A point on the constraining line.

Definition at line 206 of file variational_smoother_constraint.h.

Referenced by contains_point(), intersect(), operator<(), and point().

◆ _tol

Real libMesh::LineConstraint::_tol
private

Tolerance to use for numerical comparisons.

Definition at line 216 of file variational_smoother_constraint.h.

Referenced by contains_point(), intersect(), is_parallel(), is_parallel(), LineConstraint(), operator<(), operator==(), and tol().


The documentation for this class was generated from the following files: