$extrastylesheet
#include <sphere.h>

Public Member Functions | |
| Sphere () | |
| Sphere (const Point &c, const Real r) | |
| Sphere (const Point &, const Point &, const Point &, const Point &) | |
| Sphere (const Sphere &other_sphere) | |
| ~Sphere () | |
| void | create_from_center_radius (const Point &c, const Real r) |
| bool | intersects (const Sphere &other_sphere) const |
| Real | distance (const Sphere &other_sphere) const |
| bool | above_surface (const Point &p) const |
| bool | below_surface (const Point &p) const |
| bool | on_surface (const Point &p) const |
| Point | closest_point (const Point &p) const |
| Point | unit_normal (const Point &p) const |
| Real | radius () const |
| Real & | radius () |
| const Point & | center () const |
| Point & | center () |
| Point | surface_coords (const Point &cart) const |
| Point | world_coords (const Point &sph) const |
Private Attributes | |
| Point | _cent |
| Real | _rad |
This class defines a sphere. It also computes coordinate transformations between cartesian
and spherical
coordinates. The spherical coordinates are valid in the ranges:



The coordinates are related as follows:
is the angle in the xy plane starting with 0. from the positive x axis,
is measured against the positive z axis.
* * \ | Z * \theta| * \ | . * \ | . * \ | . * \ | . * \|. * --------------+---------.--------- * /|\ . Y * /phi\ . * / | \ . * / | \ . * /.........\ * / | * X / *
| libMesh::Sphere::Sphere | ( | const Point & | c, |
| const Real | r | ||
| ) |
Constructs a sphere of radius r centered at c.
Definition at line 43 of file sphere.C.
References create_from_center_radius().
{
libmesh_assert_greater (r, 0.);
this->create_from_center_radius (c, r);
}
| libMesh::Sphere::Sphere | ( | const Point & | pa, |
| const Point & | pb, | ||
| const Point & | pc, | ||
| const Point & | pd | ||
| ) |
Constructs a sphere connecting four points
Definition at line 62 of file sphere.C.
References std::abs(), create_from_center_radius(), libMesh::TypeTensor< T >::det(), libMesh::Real, and libMesh::TypeVector< T >::size_sq().
{
Point pad = pa - pd;
Point pbd = pb - pd;
Point pcd = pc - pd;
TensorValue<Real> T(pad,pbd,pcd);
Real D = T.det();
// The points had better not be coplanar
libmesh_assert_greater (std::abs(D), 1e-12);
Real e = 0.5*(pa.size_sq() - pd.size_sq());
Real f = 0.5*(pb.size_sq() - pd.size_sq());
Real g = 0.5*(pc.size_sq() - pd.size_sq());
TensorValue<Real> T1(e,pad(1),pad(2),
f,pbd(1),pbd(2),
g,pcd(1),pcd(2));
Real sx = T1.det()/D;
TensorValue<Real> T2(pad(0),e,pad(2),
pbd(0),f,pbd(2),
pcd(0),g,pcd(2));
Real sy = T2.det()/D;
TensorValue<Real> T3(pad(0),pad(1),e,
pbd(0),pbd(1),f,
pcd(0),pcd(1),g);
Real sz = T3.det()/D;
Point c(sx,sy,sz);
Real r = (c-pa).size();
this->create_from_center_radius(c,r);
}
| libMesh::Sphere::Sphere | ( | const Sphere & | other_sphere | ) |
Copy-constructor.
Definition at line 53 of file sphere.C.
References center(), create_from_center_radius(), and radius().
: Surface() { this->create_from_center_radius (other_sphere.center(), other_sphere.radius()); }
| bool libMesh::Sphere::above_surface | ( | const Point & | p | ) | const [virtual] |
Implements libMesh::Surface.
Definition at line 140 of file sphere.C.
References center(), radius(), and libMesh::TypeVector< T >::size().
Referenced by below_surface().
| bool libMesh::Sphere::below_surface | ( | const Point & | p | ) | const [virtual] |
Implements libMesh::Surface.
Definition at line 155 of file sphere.C.
References above_surface(), and radius().
{
libmesh_assert_greater (this->radius(), 0.);
return ( !this->above_surface (p) );
}
| const Point& libMesh::Sphere::center | ( | ) | const [inline] |
Definition at line 162 of file sphere.h.
References _cent.
Referenced by above_surface(), closest_point(), create_from_center_radius(), distance(), on_surface(), Sphere(), surface_coords(), unit_normal(), and world_coords().
{ return _cent; }
| Point& libMesh::Sphere::center | ( | ) | [inline] |
| Point libMesh::Sphere::closest_point | ( | const Point & | p | ) | const [virtual] |
Implements libMesh::Surface.
Definition at line 181 of file sphere.C.
References center(), radius(), and unit_normal().
{
libmesh_assert_greater (this->radius(), 0.);
// get the normal from the surface in the direction
// of p
Point normal = this->unit_normal (p);
// The closest point on the sphere is in the direction
// of the normal a distance r from the center.
const Point cp = this->center() + normal*this->radius();
return cp;
}
| void libMesh::Sphere::create_from_center_radius | ( | const Point & | c, |
| const Real | r | ||
| ) |
| Real libMesh::Sphere::distance | ( | const Sphere & | other_sphere | ) | const |
Definition at line 128 of file sphere.C.
References center(), radius(), and libMesh::Real.
Referenced by intersects().
| bool libMesh::Sphere::intersects | ( | const Sphere & | other_sphere | ) | const |
Definition at line 121 of file sphere.C.
References distance().
{
return distance(other_sphere) < 0 ? true : false;
}
| bool libMesh::Sphere::on_surface | ( | const Point & | p | ) | const [virtual] |
Implements libMesh::Surface.
Definition at line 164 of file sphere.C.
References std::abs(), center(), radius(), and libMesh::TypeVector< T >::size().
{
libmesh_assert_greater (this->radius(), 0.);
// Create a vector from the center to the point.
const Point w = p - this->center();
// if the size of that vector is the same as the radius() then
// the point is on the surface.
if (std::abs(w.size() - this->radius()) < 1.e-10)
return true;
return false;
}
| Real libMesh::Sphere::radius | ( | ) | const [inline] |
Returns the radius of the sphere.
Definition at line 152 of file sphere.h.
References _rad.
Referenced by above_surface(), below_surface(), closest_point(), create_from_center_radius(), distance(), on_surface(), Sphere(), and unit_normal().
{ return _rad; }
| Real& libMesh::Sphere::radius | ( | ) | [inline] |
| Point libMesh::Sphere::surface_coords | ( | const Point & | cart | ) | const [inline, virtual] |
cart. Reimplemented from libMesh::Surface.
Definition at line 201 of file sphere.h.
References center(), libMesh::pi, libMesh::Real, and libMesh::TypeVector< T >::size().
{
// constant translation in the origin
const Point c (cart-this->center());
// phi: special care, so that it gives 0..2pi results
const Real phi = std::atan2(c(1), c(0));
return Point(/* radius */ c.size(),
/* theta */ std::atan2( std::sqrt( c(0)*c(0) + c(1)*c(1) ), c(2) ),
/* phi */ ( (phi < 0) ? 2.*libMesh::pi+phi : phi ) );
}
| Point libMesh::Sphere::unit_normal | ( | const Point & | p | ) | const [virtual] |
Implements libMesh::Surface.
Definition at line 198 of file sphere.C.
References center(), radius(), and libMesh::TypeVector< T >::unit().
Referenced by closest_point().
| Point libMesh::Sphere::world_coords | ( | const Point & | sph | ) | const [inline, virtual] |
sph. Reimplemented from libMesh::Surface.
Definition at line 217 of file sphere.h.
References center(), and libMesh::Real.
{
const Real r = sph(0);
const Real theta = sph(1);
const Real phi = sph(2);
// constant translation out of the origin
return Point (/* x */ r*std::sin(theta)*std::cos(phi) + this->center()(0),
/* y */ r*std::sin(theta)*std::sin(phi) + this->center()(1),
/* z */ r*std::cos(theta) + this->center()(2));
}
Point libMesh::Sphere::_cent [private] |
Real libMesh::Sphere::_rad [private] |