https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
12namespace CSG
13{
14
15CSGPlane::CSGPlane(const std::string & name, const Point & p1, const Point & p2, const Point & p3)
16 : CSGSurface(name)
17{
18 coeffsFromPoints(p1, p2, p3);
20}
21
22CSGPlane::CSGPlane(const std::string & name, const Real a, const Real b, const Real c, const Real d)
23 : CSGSurface(name), _a(a), _b(b), _c(c), _d(d)
24{
26}
27
28std::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
35void
36CSGPlane::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
54void
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
64Real
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
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
void coeffsFromPoints(const Point &p1, const Point &p2, const Point &p3)
Definition CSGPlane.C:36
Real _b
Value of b in equation of plane.
Definition CSGPlane.h:90
Real _a
Value of a in equation of plane.
Definition CSGPlane.h:87
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
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
Real _d
Value of d in equation of plane.
Definition CSGPlane.h:96
Real _c
Value of c in equation of plane.
Definition CSGPlane.h:93
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
void normalizePlaneCoefficients()
Normalize plane coefficients so that a^2 + b^2 + c^2 = 1.
Definition CSGPlane.C:55
CSGSurface creates an internal representation of a Constructive Solid Geometry (CSG) surface,...
Definition CSGSurface.h:27
TypeVector< typename CompareTypes< T, T2 >::supertype > cross(const TypeVector< T2 > &v) const