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 Pointpoint () const
 Const getter for the _point attribute.
 
const Pointdirection () const
 Const getter for the _direction attribute.
 
const Realtol () 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 direction of the constraining line.
tolThe tolerance to use for numerical comparisons.

Definition at line 79 of file variational_smoother_constraint.C.

81{
82 libmesh_error_msg_if(_direction.norm() < _tol,
83 "Can't define a line with zero magnitude direction vector.");
84}
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 103 of file variational_smoother_constraint.C.

104{
105 // If the point lies on the line, then the vector p - point is parallel to the
106 // line In that case, the cross product of p - point with the line's direction
107 // will be zero.
108 return _direction.cross(p.point() - _point).norm() < _tol;
109}
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 121 of file variational_smoother_constraint.C.

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

112{
113 return _direction.absolute_fuzzy_equals(l.direction(), _tol);
114}
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(), and libMesh::PlaneConstraint::is_parallel().

◆ 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 116 of file variational_smoother_constraint.C.

117{
118 return _direction * p.normal() < _tol;
119}

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 86 of file variational_smoother_constraint.C.

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

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 96 of file variational_smoother_constraint.C.

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

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: