Line data Source code
1 : //* This file is part of the MOOSE framework 2 : //* https://mooseframework.inl.gov 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 : #pragma once 11 : 12 : #include "GeometryBase.h" 13 : #include "libmesh/point.h" 14 : #include "libmesh/sphere.h" 15 : 16 : class LineSegment; 17 : 18 : /** 19 : * Ball primitive: a circle in 2D or a sphere in 3D. 20 : * 21 : * Why not just use libMesh::Sphere? 22 : * - libMesh::Sphere is 3D only; Ball supports both 2D and 3D in a single type. 23 : * - Ball provides the operations the framework geometries layer needs: 24 : * intersection with a LineSegment and a tight bounding ball used for fast 25 : * nearest-neighbor / spatial searches. libMesh::Sphere exposes a different 26 : * set of surface queries (closest point, normal, above/below surface) that 27 : * we do not need here. 28 : * - Ball derives from GeometryBase so every framework geometry primitive can 29 : * be used through one virtual interface. 30 : * 31 : * If a caller does need the libMesh surface-query interface (e.g. ray tracing), 32 : * use `toSphere()` to convert. 33 : */ 34 : class Ball : public GeometryBase 35 : { 36 : public: 37 0 : Ball(const libMesh::Point & c, libMesh::Real r) : _c(c), _r(r) {} 38 : 39 0 : ~Ball() override = default; 40 : 41 : const libMesh::Point & center() const { return _c; } 42 : libMesh::Real radius() const { return _r; } 43 : 44 : /** 45 : * Check if a line segment intersects this ball. 46 : */ 47 : bool intersect(const LineSegment & line_segment) const override; 48 : 49 : /** 50 : * return the ball itself 51 : */ 52 : Ball computeBoundingBall() const override; 53 : 54 : #if LIBMESH_DIM > 2 55 : libMesh::Sphere toSphere() const { return libMesh::Sphere(_c, _r); } 56 : #endif 57 : 58 : private: 59 : libMesh::Point _c; 60 : libMesh::Real _r; 61 : };