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

Represents a plane constraint defined by a point and normal vector. More...

#include <variational_smoother_constraint.h>

Public Member Functions

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

Private Attributes

Point _point
 A point on the constraining plane.
 
Point _normal
 The direction normal to the constraining plane.
 
Real _tol
 Tolerance to use for numerical comparisons.
 

Detailed Description

Represents a plane constraint defined by a point and normal vector.

Definition at line 222 of file variational_smoother_constraint.h.

Constructor & Destructor Documentation

◆ PlaneConstraint() [1/2]

libMesh::PlaneConstraint::PlaneConstraint ( )
default

◆ PlaneConstraint() [2/2]

libMesh::PlaneConstraint::PlaneConstraint ( const Point &  point,
const Point &  normal,
const Real &  tol = TOLERANCE * TOLERANCE 
)

Constructor.

Parameters
pointA point on the constraining plane.
normalthe unit normal of the constraining plane.
tolThe tolerance to use for numerical comparisons.

Definition at line 180 of file variational_smoother_constraint.C.

182{
183 libmesh_assert_msg(_normal.norm() >= _tol,
184 "Can't define a plane with zero magnitude direction vector.");
185}
const Point & point() const
Const getter for the _point attribute.
const Point & normal() const
Const getter for the _normal attribute.
Point _point
A point on the constraining plane.
Point _normal
The direction normal to the constraining plane.
Real _tol
Tolerance to use for numerical comparisons.
const Real & tol() const
Const getter for the _tol attribute.
auto norm() const

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

Member Function Documentation

◆ contains_line()

bool libMesh::PlaneConstraint::contains_line ( const LineConstraint &  l) const

Query whether a line lies on the plane.

Parameters
lThe line in question
Returns
bool indicating whether l lies on the plane.

Definition at line 221 of file variational_smoother_constraint.C.

222{
223 const bool base_on_plane = this->contains_point(PointConstraint(l.point()));
224 const bool dir_orthogonal = std::abs(_normal * l.direction()) < _tol;
225 return base_on_plane && dir_orthogonal;
226}
bool contains_point(const PointConstraint &p) const
Query whether a point lies on the plane.

References _normal, _tol, contains_point(), libMesh::LineConstraint::direction(), and libMesh::LineConstraint::point().

Referenced by intersect().

◆ contains_point()

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

Query whether a point lies on the plane.

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

Definition at line 214 of file variational_smoother_constraint.C.

215{
216 // distance between the point and the plane
217 const Real dist = (p.point() - _point) * _normal;
218 return std::abs(dist) < _tol;
219}
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

References _normal, _point, _tol, libMesh::PointConstraint::point(), and libMesh::Real.

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

◆ intersect()

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

Computes the intersection of this plane with another constraint.

Handles intersection with PlaneConstraint, LineConstraint, 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 228 of file variational_smoother_constraint.C.

229{
230 // using visit to resolve the variant to its actual type
231 return std::visit(
232 [&](auto && o) -> ConstraintVariant {
233 // Use std::decay_t to strip references/const/volatile from o's type,
234 // so we can match the actual stored variant type in std::is_same_v.
235 using T = std::decay_t<decltype(o)>;
236 if constexpr (std::is_same_v<T, PlaneConstraint>)
237 {
238 // If planes are identical, return one of them
239 if (*this == o)
240 return *this;
241
242 if (this->is_parallel(o))
243 // Planes are parallel and do not intersect
244 return InvalidConstraint();
245
246 // Solve for a point on the intersection line of two planes.
247 // Given planes:
248 // Plane 1: n1 · (x - p1) = 0
249 // Plane 2: n2 · (x - p2) = 0
250 // The line of intersection has direction dir = n1 × n2.
251 // To find a point on this line, we assume:
252 // x = p1 + s·n1 = p2 + t·n2
253 // ⇒ p1 - p2 = t·n2 - s·n1
254 // Taking dot products with n1 and n2 leads to:
255 // [-n1·n1 n1·n2] [s] = [n1 · (p1 - p2)]
256 // [-n1·n2 n2·n2] [t] [n2 · (p1 - p2)]
257
258 const Point dir = this->_normal.cross(o.normal()); // direction of line of intersection
259 libmesh_assert(dir.norm() > _tol);
260 const Point w = _point - o.point();
261
262 // Dot product terms used in 2x2 system
263 const Real n1_dot_n2 = _normal * o.normal();
264 const Real n2_dot_n2 = o.normal() * o.normal();
265 const Real n1_dot_w = _normal * w;
266 const Real n2_dot_w = o.normal() * w;
267
268 // By Lagrange's identity the determinant
269 // -(n1.n1 * n2.n2 - (n1.n2)^2) equals -|n1 x n2|^2, which is
270 // nonzero because the planes are not parallel. Computing it from
271 // dir avoids the cancellation in 1 - cos^2 for nearly parallel
272 // planes.
273 const Real denom = -dir.norm_sq();
274
275 const Real s = -(n1_dot_n2 * n2_dot_w - n2_dot_n2 * n1_dot_w) / denom;
276 const Point p0 = _point + s * _normal;
277
278 return LineConstraint{p0, dir.unit()};
279 }
280
281 else if constexpr (std::is_same_v<T, LineConstraint>)
282 {
283 if (this->contains_line(o))
284 return o;
285
286 if (this->is_parallel(o))
287 // Line is parallel and does not intersect the plane
288 return InvalidConstraint();
289
290 // Solve for t in the parametric equation:
291 // p(t) = point + t·d
292 // such that this point also satisfies the plane equation:
293 // n · (p(t) - p0) = 0
294 // which leads to:
295 // t = (n · (p0 - point)) / (n · d)
296
297 const Real denom = _normal * o.direction();
298 libmesh_assert(std::abs(denom) > _tol);
299 const Real t = (_normal * (_point - o.point())) / denom;
300 return PointConstraint{o.point() + t * o.direction()};
301 }
302
303 else if constexpr (std::is_same_v<T, PointConstraint>)
304 {
305 if (!this->contains_point(o))
306 // Point is not on the plane
307 return InvalidConstraint();
308
309 return o;
310 }
311
312 else
313 libmesh_error_msg("Unsupported constraint type in Plane::intersect.");
314 },
315 other);
316}
bool is_parallel(const PlaneConstraint &p) const
Query whether a plane is parallel to this plane.
bool contains_line(const LineConstraint &l) const
Query whether a line lies on the plane.
TypeVector< typename CompareTypes< T, T2 >::supertype > cross(const TypeVector< T2 > &v) const
LIBMESH_DEVICE_INLINE TypeVector< T > unit() const
auto norm_sq() const
libmesh_assert(ctx)
std::variant< PointConstraint, LineConstraint, PlaneConstraint, InvalidConstraint > ConstraintVariant
Type used to store a constraint that may be a PlaneConstraint, LineConstraint, or PointConstraint.

References _normal, _point, _tol, contains_line(), contains_point(), libMesh::TypeVector< T >::cross(), is_parallel(), libMesh::libmesh_assert(), libMesh::TypeVector< T >::norm(), libMesh::TypeVector< T >::norm_sq(), libMesh::PointConstraint::point(), libMesh::Real, and libMesh::TypeVector< T >::unit().

◆ is_parallel() [1/2]

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

Query whether a line is parallel to this plane.

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

Definition at line 212 of file variational_smoother_constraint.C.

212{ return l.is_parallel(*this); }

References libMesh::LineConstraint::is_parallel().

◆ is_parallel() [2/2]

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

Query whether a plane is parallel to this plane.

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

Definition at line 204 of file variational_smoother_constraint.C.

205{
206 // |n1 x n2| is the sine of the angle between the unit normals, and its
207 // square is the determinant that intersect() divides by, so any pair of
208 // planes that fails this test can be intersected.
209 return _normal.cross(p.normal()).norm() <= _tol;
210}

References _normal, _tol, libMesh::TypeVector< T >::cross(), and normal().

Referenced by intersect(), and MeshSmootherTest::testConstraintNearlyParallelPlanes().

◆ normal()

const Point & libMesh::PlaneConstraint::normal ( ) const
inline

Const getter for the _normal attribute.

Definition at line 301 of file variational_smoother_constraint.h.

301{ return _normal; }

References _normal.

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

◆ operator<()

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

Comparison operator for ordering PlaneConstraint objects.

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

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

Definition at line 187 of file variational_smoother_constraint.C.

188{
189 if (*this == other)
190 return false;
191
192 if (!(_normal.absolute_fuzzy_equals(other.normal(), _tol)))
193 return _normal < other.normal();
194 return (_normal * _point) < (other.normal() * other.point());
195}
bool absolute_fuzzy_equals(const TypeVector< T > &rhs, Real tol=TOLERANCE) const

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

◆ operator==()

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

Equality operator.

Parameters
otherThe PlaneConstraint to compare with.
Returns
True if both PlaneConstraints represent the same plane.

Definition at line 197 of file variational_smoother_constraint.C.

198{
199 if (!(_normal.absolute_fuzzy_equals(other.normal(), _tol)))
200 return false;
201 return this->contains_point(other.point());
202}

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

◆ point()

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

Const getter for the _point attribute.

Definition at line 296 of file variational_smoother_constraint.h.

296{ return _point; }

References _point.

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

◆ tol()

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

Const getter for the _tol attribute.

Definition at line 306 of file variational_smoother_constraint.h.

306{ return _tol; }

References _tol.

Member Data Documentation

◆ _normal

Point libMesh::PlaneConstraint::_normal
private

The direction normal to the constraining plane.

Definition at line 318 of file variational_smoother_constraint.h.

Referenced by contains_line(), contains_point(), intersect(), is_parallel(), normal(), operator<(), operator==(), and PlaneConstraint().

◆ _point

Point libMesh::PlaneConstraint::_point
private

A point on the constraining plane.

Definition at line 313 of file variational_smoother_constraint.h.

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

◆ _tol

Real libMesh::PlaneConstraint::_tol
private

Tolerance to use for numerical comparisons.

Definition at line 323 of file variational_smoother_constraint.h.

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


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