https://mooseframework.inl.gov
CSGPlane.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #include "CSGPlane.h"
11 
12 namespace CSG
13 {
14 
15 CSGPlane::CSGPlane(const std::string & name, const Point & p1, const Point & p2, const Point & p3)
17 {
18  coeffsFromPoints(p1, p2, p3);
19 }
20 
21 CSGPlane::CSGPlane(const std::string & name, const Real a, const Real b, const Real c, const Real d)
22  : CSGSurface(name, MooseUtils::prettyCppType<CSGPlane>()), _a(a), _b(b), _c(c), _d(d)
23 {
24 }
25 
26 std::unordered_map<std::string, Real>
28 {
29  std::unordered_map<std::string, Real> coeffs = {{"a", _a}, {"b", _b}, {"c", _c}, {"d", _d}};
30  return coeffs;
31 }
32 
33 void
34 CSGPlane::coeffsFromPoints(const Point & p1, const Point & p2, const Point & p3)
35 {
36  // Use three points on plane to solve for the plane equation in form aX + bY +cZ = d,
37  // where we are solving for a, b, c, and d.
38  RealVectorValue v1 = p2 - p1;
39  RealVectorValue v2 = p3 - p1;
40  RealVectorValue cross = v2.cross(v1);
41 
42  // Check that provided points aren't collinear
43  if (MooseUtils::absoluteFuzzyEqual(cross.norm(), 0))
44  mooseError("Provided points to define a CSGPlane are collinear");
45 
46  _a = cross(0);
47  _b = cross(1);
48  _c = cross(2);
49  _d = cross * (RealVectorValue)p1;
50 }
51 
52 Real
54 {
55  // Compute dot product of <a, b, c> and p to determine if p lies
56  // in the positive or negative halfspace of the plane
57  const Real dot_prod = _a * p(0) + _b * p(1) + _c * p(2);
58 
59  return dot_prod - _d;
60 }
61 } // namespace CSG
virtual Real evaluateSurfaceEquationAtPoint(const Point &p) const override
given a point, determine its evaluation based on the equation of the plane
Definition: CSGPlane.C:53
std::string name(const ElemQuality q)
auto norm() const -> decltype(std::norm(Real()))
bool absoluteFuzzyEqual(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether two variables are equal within an absolute tolerance.
Definition: MooseUtils.h:382
Real _a
Value of a in equation of plane.
Definition: CSGPlane.h:74
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:323
CSGPlane creates an internal representation of a Constructive Solid Geometry (CSG) plane...
Definition: CSGPlane.h:23
CSGPlane(const std::string &name, const Point &p1, const Point &p2, const Point &p3)
Construct a new CSGPlane surface from three non co-linear points.
Definition: CSGPlane.C:15
TypeVector< typename CompareTypes< Real, T2 >::supertype > cross(const TypeVector< T2 > &v) const
Real _b
Value of b in equation of plane.
Definition: CSGPlane.h:77
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Real _d
Value of d in equation of plane.
Definition: CSGPlane.h:83
CSGSurface creates an internal representation of a Constructive Solid Geometry (CSG) surface...
Definition: CSGSurface.h:26
Real _c
Value of c in equation of plane.
Definition: CSGPlane.h:80
void coeffsFromPoints(const Point &p1, const Point &p2, const Point &p3)
Definition: CSGPlane.C:34
virtual std::unordered_map< std::string, Real > getCoeffs() const override
get coefficients (a, b, c, d) of the Plane aX + bY + cZ = d
Definition: CSGPlane.C:27
std::string prettyCppType(const std::string &cpp_type)
Definition: MooseUtils.C:1151