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);
20 }
21 
22 CSGPlane::CSGPlane(const std::string & name, const Real a, const Real b, const Real c, const Real d)
23  : CSGSurface(name, MooseUtils::prettyCppType<CSGPlane>()), _a(a), _b(b), _c(c), _d(d)
24 {
26 }
27 
28 std::unordered_map<std::string, Real>
30 {
31  std::unordered_map<std::string, Real> coeffs = {{"a", _a}, {"b", _b}, {"c", _c}, {"d", _d}};
32  return coeffs;
33 }
34 
35 void
36 CSGPlane::coeffsFromPoints(const Point & p1, const Point & p2, const Point & p3)
37 {
38  // Use three points on plane to solve for the plane equation in form aX + bY +cZ = d,
39  // where we are solving for a, b, c, and d.
40  RealVectorValue v1 = p2 - p1;
41  RealVectorValue v2 = p3 - p1;
42  RealVectorValue cross = v2.cross(v1);
43 
44  // Check that provided points aren't collinear
45  if (MooseUtils::absoluteFuzzyEqual(cross.norm(), 0))
46  mooseError("Provided points to define a CSGPlane are collinear");
47 
48  _a = cross(0);
49  _b = cross(1);
50  _c = cross(2);
51  _d = cross * (RealVectorValue)p1;
52 }
53 
54 void
56 {
57  const auto k = 1. / std::sqrt(_a * _a + _b * _b + _c * _c);
58  _a *= k;
59  _b *= k;
60  _c *= k;
61  _d *= k;
62 }
63 
64 Real
66 {
67  // Compute dot product of <a, b, c> and p to determine if p lies
68  // in the positive or negative halfspace of the plane
69  const Real dot_prod = _a * p(0) + _b * p(1) + _c * p(2);
70 
71  return dot_prod - _d;
72 }
73 } // 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:65
std::string name(const ElemQuality q)
auto norm() const -> decltype(std::norm(Real()))
Real _a
Value of a in equation of plane.
Definition: CSGPlane.h:87
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
void normalizePlaneCoefficients()
Normalize plane coefficients so that a^2 + b^2 + c^2 = 1.
Definition: CSGPlane.C:55
TypeVector< typename CompareTypes< Real, T2 >::supertype > cross(const TypeVector< T2 > &v) const
Real _b
Value of b in equation of plane.
Definition: CSGPlane.h:90
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
CTSub CT_OPERATOR_BINARY CTMul CTCompareLess CTCompareGreater CTCompareEqual _arg template * sqrt(_arg)) *_arg.template D< dtag >()) CT_SIMPLE_UNARY_FUNCTION(tanh
Real _d
Value of d in equation of plane.
Definition: CSGPlane.h:96
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:93
void coeffsFromPoints(const Point &p1, const Point &p2, const Point &p3)
Definition: CSGPlane.C:36
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:29
std::string prettyCppType(const std::string &cpp_type)
Definition: MooseUtils.C:1151