libMesh
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. More...
 
bool operator< (const PlaneConstraint &other) const
 Comparison operator for ordering PlaneConstraint objects. More...
 
bool operator== (const PlaneConstraint &other) const
 Equality operator. More...
 
bool contains_point (const PointConstraint &p) const
 Query whether a point lies on the plane. More...
 
bool contains_line (const LineConstraint &l) const
 Query whether a line lies on the plane. More...
 
bool is_parallel (const PlaneConstraint &p) const
 Query whether a plane is parallel to this plane. More...
 
bool is_parallel (const LineConstraint &l) const
 Query whether a line is parallel to this plane. More...
 
ConstraintVariant intersect (const ConstraintVariant &other) const
 Computes the intersection of this plane with another constraint. More...
 
const Pointpoint () const
 Const getter for the _point attribute. More...
 
const Pointnormal () const
 Const getter for the _normal attribute. More...
 
const Realtol () const
 Const getter for the _tol attribute. More...
 

Private Attributes

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

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 direction normal to the constraining plane.
tolThe tolerance to use for numerical comparisons.

Definition at line 179 of file variational_smoother_constraint.C.

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

181 {
182  libmesh_error_msg_if(_normal.norm() < _tol,
183  "Can't define a plane with zero magnitude direction vector.");
184 }
const Point & normal() const
Const getter for the _normal attribute.
auto norm() const -> decltype(std::norm(T()))
Definition: type_vector.h:907
Point _point
A point on the constraining plane.
Point _normal
The direction normal to the constraining plane.
const Point & point() const
Const getter for the _point attribute.
const Real & tol() const
Const getter for the _tol attribute.
Real _tol
Tolerance to use for numerical comparisons.

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

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

Referenced by intersect().

218 {
219  const bool base_on_plane = this->contains_point(PointConstraint(l.point()));
220  const bool dir_orthogonal = std::abs(_normal * l.direction()) < _tol;
221  return base_on_plane && dir_orthogonal;
222 }
bool contains_point(const PointConstraint &p) const
Query whether a point lies on the plane.
Point _normal
The direction normal to the constraining plane.
Real _tol
Tolerance to use for numerical comparisons.

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

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

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

211 {
212  // distance between the point and the plane
213  const Real dist = (p.point() - _point) * _normal;
214  return std::abs(dist) < _tol;
215 }
Point _point
A point on the constraining plane.
Point _normal
The direction normal to the constraining plane.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Real _tol
Tolerance to use for numerical comparisons.

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

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

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

◆ is_parallel() [1/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 203 of file variational_smoother_constraint.C.

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

Referenced by intersect().

204 {
205  return _normal.absolute_fuzzy_equals(p.normal(), _tol);
206 }
Point _normal
The direction normal to the constraining plane.
bool absolute_fuzzy_equals(const TypeVector< T > &rhs, Real tol=TOLERANCE) const
Definition: type_vector.h:972
Real _tol
Tolerance to use for numerical comparisons.

◆ is_parallel() [2/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 208 of file variational_smoother_constraint.C.

References libMesh::LineConstraint::is_parallel().

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

◆ normal()

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

Const getter for the _normal attribute.

Definition at line 301 of file variational_smoother_constraint.h.

References _normal.

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

301 { return _normal; }
Point _normal
The direction normal to the constraining plane.

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

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

187 {
188  if (*this == other)
189  return false;
190 
191  if (!(_normal.absolute_fuzzy_equals(other.normal(), _tol)))
192  return _normal < other.normal();
193  return (_normal * _point) < (other.normal() * other.point());
194 }
Point _point
A point on the constraining plane.
Point _normal
The direction normal to the constraining plane.
bool absolute_fuzzy_equals(const TypeVector< T > &rhs, Real tol=TOLERANCE) const
Definition: type_vector.h:972
Real _tol
Tolerance to use for numerical comparisons.

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

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

197 {
198  if (!(_normal.absolute_fuzzy_equals(other.normal(), _tol)))
199  return false;
200  return this->contains_point(other.point());
201 }
bool contains_point(const PointConstraint &p) const
Query whether a point lies on the plane.
Point _normal
The direction normal to the constraining plane.
bool absolute_fuzzy_equals(const TypeVector< T > &rhs, Real tol=TOLERANCE) const
Definition: type_vector.h:972
Real _tol
Tolerance to use for numerical comparisons.

◆ point()

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

Const getter for the _point attribute.

Definition at line 296 of file variational_smoother_constraint.h.

References _point.

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

296 { return _point; }
Point _point
A point on the constraining plane.

◆ tol()

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

Const getter for the _tol attribute.

Definition at line 306 of file variational_smoother_constraint.h.

References _tol.

306 { return _tol; }
Real _tol
Tolerance to use for numerical comparisons.

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: