libMesh
Public Member Functions | Private Attributes | List of all members
libMesh::Sphere Class Reference


This class defines a sphere. More...

#include <sphere.h>

Inheritance diagram for libMesh::Sphere:
[legend]

Public Member Functions

 Sphere ()
 Dummy Constructor. More...
 
 Sphere (const Point &c, const Real r)
 Constructs a sphere of radius r centered at c. More...
 
 Sphere (const Point &, const Point &, const Point &, const Point &)
 Constructs a sphere connecting four points. More...
 
 Sphere (const Sphere &other_sphere)
 Copy-constructor. More...
 
 ~Sphere ()
 Destructor. More...
 
void create_from_center_radius (const Point &c, const Real r)
 Defines a sphere of radius r centered at c. More...
 
bool intersects (const Sphere &other_sphere) const
 
Real distance (const Sphere &other_sphere) const
 
virtual bool above_surface (const Point &p) const override
 
virtual bool below_surface (const Point &p) const override
 
virtual bool on_surface (const Point &p) const override
 
virtual Point closest_point (const Point &p) const override
 
virtual Point unit_normal (const Point &p) const override
 
Real radius () const
 
Realradius ()
 
const Pointcenter () const
 
Pointcenter ()
 
virtual Point surface_coords (const Point &cart) const override
 
virtual Point world_coords (const Point &sph) const override
 

Private Attributes

Point _cent
 The center of the sphere. More...
 
Real _rad
 The radius of the sphere. More...
 

Detailed Description


This class defines a sphere.

It also computes coordinate transformations between cartesian $ (x, y, z) $ and spherical $ (r, \theta, \phi) $ coordinates. The spherical coordinates are valid in the ranges:

The coordinates are related as follows: $ \phi $ is the angle in the xy plane starting with 0. from the positive x axis, $ \theta $ is measured against the positive z axis.

*
*        \      | Z
*         \theta|
*          \    |    .
*           \   |   .
*            \  |  .
*             \ | .
*              \|.
* --------------+---------.---------
*              /|\       .          Y
*             /phi\     .
*            /  |  \   .
*           /   |   \ .
*          /.........\
*         /     |
*      X /
* 
Author
Benjamin S. Kirk, Daniel Dreyer
Date
2002-2007 A geometric object representing a sphere.

Definition at line 72 of file sphere.h.

Constructor & Destructor Documentation

◆ Sphere() [1/4]

libMesh::Sphere::Sphere ( )

Dummy Constructor.

◆ Sphere() [2/4]

libMesh::Sphere::Sphere ( const Point c,
const Real  r 
)

Constructs a sphere of radius r centered at c.

◆ Sphere() [3/4]

libMesh::Sphere::Sphere ( const Point ,
const Point ,
const Point ,
const Point  
)

Constructs a sphere connecting four points.

◆ Sphere() [4/4]

libMesh::Sphere::Sphere ( const Sphere other_sphere)

Copy-constructor.

◆ ~Sphere()

libMesh::Sphere::~Sphere ( )

Destructor.

Does nothing at the moment.

Member Function Documentation

◆ above_surface()

virtual bool libMesh::Sphere::above_surface ( const Point p) const
overridevirtual
Returns
true if the point p is above the surface, false otherwise.

Implements libMesh::Surface.

◆ below_surface()

virtual bool libMesh::Sphere::below_surface ( const Point p) const
overridevirtual
Returns
true if the point p is below the surface, false otherwise.

Implements libMesh::Surface.

◆ center() [1/2]

const Point& libMesh::Sphere::center ( ) const
Returns
The center of the sphere.

Definition at line 163 of file sphere.h.

References _cent.

Referenced by surface_coords(), and world_coords().

163 { return _cent; }
Point _cent
The center of the sphere.
Definition: sphere.h:188

◆ center() [2/2]

Point& libMesh::Sphere::center ( )
Returns
The center of the sphere.

Definition at line 168 of file sphere.h.

References _cent.

168 { return _cent; }
Point _cent
The center of the sphere.
Definition: sphere.h:188

◆ closest_point()

virtual Point libMesh::Sphere::closest_point ( const Point p) const
overridevirtual
Returns
The closest point on the surface to point p.

Implements libMesh::Surface.

◆ create_from_center_radius()

void libMesh::Sphere::create_from_center_radius ( const Point c,
const Real  r 
)

Defines a sphere of radius r centered at c.

◆ distance()

Real libMesh::Sphere::distance ( const Sphere other_sphere) const
Returns
The distance between the surface of this sphere and another sphere.

◆ intersects()

bool libMesh::Sphere::intersects ( const Sphere other_sphere) const
Returns
true if other_sphere intersects this sphere, false otherwise.

◆ on_surface()

virtual bool libMesh::Sphere::on_surface ( const Point p) const
overridevirtual
Returns
true if the point p is on the surface, false otherwise.
Note
The definition of "on the surface" really means "very close" to account for roundoff error.

Implements libMesh::Surface.

◆ radius() [1/2]

Real libMesh::Sphere::radius ( ) const
Returns
The radius of the sphere.

Definition at line 153 of file sphere.h.

References _rad.

153 { return _rad; }
Real _rad
The radius of the sphere.
Definition: sphere.h:193

◆ radius() [2/2]

Real& libMesh::Sphere::radius ( )
Returns
The radius of the sphere as a writable reference.

Definition at line 158 of file sphere.h.

References _rad.

158 { return _rad; }
Real _rad
The radius of the sphere.
Definition: sphere.h:193

◆ surface_coords()

Point libMesh::Sphere::surface_coords ( const Point cart) const
overridevirtual
Returns
The spherical coordinates for the cartesian coordinates cart.

Reimplemented from libMesh::Surface.

Definition at line 201 of file sphere.h.

References center(), libMesh::TypeVector< T >::norm(), libMesh::pi, and libMesh::Real.

202 {
203  // constant translation in the origin
204  const Point c (cart-this->center());
205 
206  // phi: special care, so that it gives 0..2pi results
207  const Real phi = std::atan2(c(1), c(0));
208 
209  return Point(/* radius */ c.norm(),
210  /* theta */ std::atan2( std::sqrt( c(0)*c(0) + c(1)*c(1) ), c(2) ),
211  /* phi */ ( (phi < 0) ? 2.*libMesh::pi+phi : phi ) );
212 }
const Point & center() const
Definition: sphere.h:163
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const Real pi
.
Definition: libmesh.h:233

◆ unit_normal()

virtual Point libMesh::Sphere::unit_normal ( const Point p) const
overridevirtual
Returns
A unit vector normal to the surface at point p.

Implements libMesh::Surface.

◆ world_coords()

Point libMesh::Sphere::world_coords ( const Point sph) const
overridevirtual
Returns
The cartesian coordinates for the spherical coordinates sph.

Reimplemented from libMesh::Surface.

Definition at line 217 of file sphere.h.

References center(), and libMesh::Real.

218 {
219  const Real r = sph(0);
220  const Real theta = sph(1);
221  const Real phi = sph(2);
222 
223  // constant translation out of the origin
224  return Point (/* x */ r*std::sin(theta)*std::cos(phi) + this->center()(0),
225  /* y */ r*std::sin(theta)*std::sin(phi) + this->center()(1),
226  /* z */ r*std::cos(theta) + this->center()(2));
227 }
const Point & center() const
Definition: sphere.h:163
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

Member Data Documentation

◆ _cent

Point libMesh::Sphere::_cent
private

The center of the sphere.

Definition at line 188 of file sphere.h.

Referenced by center().

◆ _rad

Real libMesh::Sphere::_rad
private

The radius of the sphere.

Definition at line 193 of file sphere.h.

Referenced by radius().


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