Line data Source code
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 434 : CSGPlane::CSGPlane(const std::string & name, const Point & p1, const Point & p2, const Point & p3)
16 434 : : CSGSurface(name, MooseUtils::prettyCppType<CSGPlane>())
17 : {
18 434 : coeffsFromPoints(p1, p2, p3);
19 432 : normalizePlaneCoefficients();
20 434 : }
21 :
22 52 : CSGPlane::CSGPlane(const std::string & name, const Real a, const Real b, const Real c, const Real d)
23 52 : : CSGSurface(name, MooseUtils::prettyCppType<CSGPlane>()), _a(a), _b(b), _c(c), _d(d)
24 : {
25 52 : normalizePlaneCoefficients();
26 52 : }
27 :
28 : std::unordered_map<std::string, Real>
29 464 : CSGPlane::getCoeffs() const
30 : {
31 2784 : std::unordered_map<std::string, Real> coeffs = {{"a", _a}, {"b", _b}, {"c", _c}, {"d", _d}};
32 464 : return coeffs;
33 464 : }
34 :
35 : void
36 434 : 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 434 : RealVectorValue v1 = p2 - p1;
41 434 : RealVectorValue v2 = p3 - p1;
42 434 : RealVectorValue cross = v2.cross(v1);
43 :
44 : // Check that provided points aren't collinear
45 434 : if (MooseUtils::absoluteFuzzyEqual(cross.norm(), 0))
46 2 : mooseError("Provided points to define a CSGPlane are collinear");
47 :
48 432 : _a = cross(0);
49 432 : _b = cross(1);
50 432 : _c = cross(2);
51 432 : _d = cross * (RealVectorValue)p1;
52 432 : }
53 :
54 : void
55 484 : CSGPlane::normalizePlaneCoefficients()
56 : {
57 484 : const auto k = 1. / std::sqrt(_a * _a + _b * _b + _c * _c);
58 484 : _a *= k;
59 484 : _b *= k;
60 484 : _c *= k;
61 484 : _d *= k;
62 484 : }
63 :
64 : Real
65 468 : CSGPlane::evaluateSurfaceEquationAtPoint(const Point & p) const
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 468 : const Real dot_prod = _a * p(0) + _b * p(1) + _c * p(2);
70 :
71 468 : return dot_prod - _d;
72 : }
73 : } // namespace CSG
|