https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
Ball Class Reference

Ball primitive: a circle in 2D or a sphere in 3D. More...

#include <Ball.h>

Inheritance diagram for Ball:
[legend]

Public Member Functions

 Ball (const libMesh::Point &c, libMesh::Real r)
 
 ~Ball () override=default
 
const libMesh::Pointcenter () const
 
libMesh::Real radius () const
 
bool intersect (const LineSegment &line_segment) const override
 Check if a line segment intersects this ball.
 
Ball computeBoundingBall () const override
 return the ball itself
 
libMesh::Sphere toSphere () const
 

Private Attributes

libMesh::Point _c
 
libMesh::Real _r
 

Detailed Description

Ball primitive: a circle in 2D or a sphere in 3D.

Why not just use libMesh::Sphere?

If a caller does need the libMesh surface-query interface (e.g. ray tracing), use toSphere() to convert.

Definition at line 34 of file Ball.h.

Constructor & Destructor Documentation

◆ Ball()

Ball::Ball ( const libMesh::Point c,
libMesh::Real  r 
)
inline

Definition at line 37 of file Ball.h.

37: _c(c), _r(r) {}
libMesh::Real _r
Definition Ball.h:60
libMesh::Point _c
Definition Ball.h:59

◆ ~Ball()

Ball::~Ball ( )
overridedefault

Member Function Documentation

◆ center()

const libMesh::Point & Ball::center ( ) const
inline

◆ computeBoundingBall()

Ball Ball::computeBoundingBall ( ) const
overridevirtual

return the ball itself

Implements GeometryBase.

Definition at line 46 of file Ball.C.

47{
48 return *this;
49}

◆ intersect()

bool Ball::intersect ( const LineSegment line_segment) const
overridevirtual

Check if a line segment intersects this ball.

Implements GeometryBase.

Definition at line 19 of file Ball.C.

20{
21 const Point & p0 = line_segment.start();
22 const Point & p1 = line_segment.end();
23 const Point d = p1 - p0;
24 const Point f = p0 - _c;
25
26 const Real a = d.norm_sq();
27 const Real b = 2.0 * (f * d);
28 const Real c = f.norm_sq() - _r * _r;
29
30 if (a == 0.0)
31 return f.norm_sq() <= _r * _r;
32
33 const Real discriminant = b * b - 4.0 * a * c;
34 if (discriminant < 0.0)
35 return false;
36
37 const Real sqrt_disc = std::sqrt(discriminant);
38 const Real inv_denom = 1.0 / (2.0 * a);
39 const Real t1 = (-b - sqrt_disc) * inv_denom;
40 const Real t2 = (-b + sqrt_disc) * inv_denom;
41
42 return (t1 >= 0.0 && t1 <= 1.0) || (t2 >= 0.0 && t2 <= 1.0);
43}
const Point & end() const
Ending of the line segment.
Definition LineSegment.h:90
const Point & start() const
Beginning of the line segment.
Definition LineSegment.h:85
auto norm_sq() const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

◆ radius()

libMesh::Real Ball::radius ( ) const
inline

◆ toSphere()

libMesh::Sphere Ball::toSphere ( ) const
inline

Definition at line 55 of file Ball.h.

Member Data Documentation

◆ _c

libMesh::Point Ball::_c
private

Definition at line 59 of file Ball.h.

Referenced by center(), intersect(), and toSphere().

◆ _r

libMesh::Real Ball::_r
private

Definition at line 60 of file Ball.h.

Referenced by intersect(), radius(), and toSphere().


The documentation for this class was generated from the following files: