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::Point & center () 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 43 of file Ball.C.

44{
45 return *this;
46}

◆ intersect()

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

Check if a line segment intersects this ball.

Implements GeometryBase.

Definition at line 16 of file Ball.C.

17{
18 const Point & p0 = line_segment.start();
19 const Point & p1 = line_segment.end();
20 const Point d = p1 - p0;
21 const Point f = p0 - _c;
22
23 const Real a = d.norm_sq();
24 const Real b = 2.0 * (f * d);
25 const Real c = f.norm_sq() - _r * _r;
26
27 if (a == 0.0)
28 return f.norm_sq() <= _r * _r;
29
30 const Real discriminant = b * b - 4.0 * a * c;
31 if (discriminant < 0.0)
32 return false;
33
34 const Real sqrt_disc = std::sqrt(discriminant);
35 const Real inv_denom = 1.0 / (2.0 * a);
36 const Real t1 = (-b - sqrt_disc) * inv_denom;
37 const Real t2 = (-b + sqrt_disc) * inv_denom;
38
39 return (t1 >= 0.0 && t1 <= 1.0) || (t2 >= 0.0 && t2 <= 1.0);
40}
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
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: