libMesh::Sphere Class Reference
#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 |
Detailed Description
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 /
- Date:
- 2002-2007
Definition at line 75 of file sphere.h.
Constructor & Destructor Documentation
| libMesh::Sphere::Sphere | ( | ) |
Constructs a sphere of radius r centered at c.
Definition at line 43 of file sphere.C.
References create_from_center_radius().
00045 { 00046 libmesh_assert_greater (r, 0.); 00047 00048 this->create_from_center_radius (c, r); 00049 }
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().
00066 { 00067 Point pad = pa - pd; 00068 Point pbd = pb - pd; 00069 Point pcd = pc - pd; 00070 00071 TensorValue<Real> T(pad,pbd,pcd); 00072 00073 Real D = T.det(); 00074 00075 // The points had better not be coplanar 00076 libmesh_assert_greater (std::abs(D), 1e-12); 00077 00078 Real e = 0.5*(pa.size_sq() - pd.size_sq()); 00079 Real f = 0.5*(pb.size_sq() - pd.size_sq()); 00080 Real g = 0.5*(pc.size_sq() - pd.size_sq()); 00081 00082 TensorValue<Real> T1(e,pad(1),pad(2), 00083 f,pbd(1),pbd(2), 00084 g,pcd(1),pcd(2)); 00085 Real sx = T1.det()/D; 00086 00087 TensorValue<Real> T2(pad(0),e,pad(2), 00088 pbd(0),f,pbd(2), 00089 pcd(0),g,pcd(2)); 00090 Real sy = T2.det()/D; 00091 00092 TensorValue<Real> T3(pad(0),pad(1),e, 00093 pbd(0),pbd(1),f, 00094 pcd(0),pcd(1),g); 00095 Real sz = T3.det()/D; 00096 00097 Point c(sx,sy,sz); 00098 Real r = (c-pa).size(); 00099 00100 this->create_from_center_radius(c,r); 00101 }
| 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().
00053 : 00054 Surface() 00055 { 00056 this->create_from_center_radius (other_sphere.center(), 00057 other_sphere.radius()); 00058 }
| libMesh::Sphere::~Sphere | ( | ) |
Member Function Documentation
| bool libMesh::Sphere::above_surface | ( | const Point & | p | ) | const [virtual] |
- Returns:
- true if the point p is above the surface, false otherwise.
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] |
- Returns:
- true if the point p is below the surface, false otherwise.
Implements libMesh::Surface.
Definition at line 155 of file sphere.C.
References above_surface(), and radius().
00156 { 00157 libmesh_assert_greater (this->radius(), 0.); 00158 00159 return ( !this->above_surface (p) ); 00160 }
| Point& libMesh::Sphere::center | ( | ) | [inline] |
| const Point& libMesh::Sphere::center | ( | ) | const [inline] |
- Returns:
- the center of the sphere.
Definition at line 165 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().
00165 { return _cent; }
- Returns:
- the closest point on the surface to point p.
Implements libMesh::Surface.
Definition at line 181 of file sphere.C.
References center(), radius(), and unit_normal().
00182 { 00183 libmesh_assert_greater (this->radius(), 0.); 00184 00185 // get the normal from the surface in the direction 00186 // of p 00187 Point normal = this->unit_normal (p); 00188 00189 // The closest point on the sphere is in the direction 00190 // of the normal a distance r from the center. 00191 const Point cp = this->center() + normal*this->radius(); 00192 00193 return cp; 00194 }
- Returns:
- the distance between the surface of this sphere and another sphere.
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 |
- Returns:
- true if other_sphere intersects this sphere, false otherwise.
Definition at line 121 of file sphere.C.
References distance().
00122 { 00123 return distance(other_sphere) < 0 ? true : false; 00124 }
| bool libMesh::Sphere::on_surface | ( | const Point & | p | ) | const [virtual] |
- Returns:
- true if the point p is on the surface, false otherwise. Note that the definition of on the surface really means "very close" to account for roundoff error.
Implements libMesh::Surface.
Definition at line 164 of file sphere.C.
References std::abs(), center(), radius(), and libMesh::TypeVector< T >::size().
00165 { 00166 libmesh_assert_greater (this->radius(), 0.); 00167 00168 // Create a vector from the center to the point. 00169 const Point w = p - this->center(); 00170 00171 // if the size of that vector is the same as the radius() then 00172 // the point is on the surface. 00173 if (std::abs(w.size() - this->radius()) < 1.e-10) 00174 return true; 00175 00176 return false; 00177 }
| Real& libMesh::Sphere::radius | ( | ) | [inline] |
| Real libMesh::Sphere::radius | ( | ) | const [inline] |
Returns the radius of the sphere.
Definition at line 155 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().
00155 { return _rad; }
- Returns:
- the spherical coordinates for the cartesian coordinates
cart.
Reimplemented from libMesh::Surface.
Definition at line 204 of file sphere.h.
References center(), libMesh::pi, libMesh::Real, and libMesh::TypeVector< T >::size().
00205 { 00206 // constant translation in the origin 00207 const Point c (cart-this->center()); 00208 00209 // phi: special care, so that it gives 0..2pi results 00210 const Real phi = std::atan2(c(1), c(0)); 00211 00212 return Point(/* radius */ c.size(), 00213 /* theta */ std::atan2( std::sqrt( c(0)*c(0) + c(1)*c(1) ), c(2) ), 00214 /* phi */ ( (phi < 0) ? 2.*libMesh::pi+phi : phi ) ); 00215 }
- Returns:
- a unit vector normal to the surface at point p.
Implements libMesh::Surface.
Definition at line 198 of file sphere.C.
References center(), radius(), and libMesh::TypeVector< T >::unit().
Referenced by closest_point().
- Returns:
- the cartesian coordinates for the spherical coordinates
sph.
Reimplemented from libMesh::Surface.
Definition at line 220 of file sphere.h.
References center(), and libMesh::Real.
00221 { 00222 const Real r = sph(0); 00223 const Real theta = sph(1); 00224 const Real phi = sph(2); 00225 00226 // constant translation out of the origin 00227 return Point (/* x */ r*std::sin(theta)*std::cos(phi) + this->center()(0), 00228 /* y */ r*std::sin(theta)*std::sin(phi) + this->center()(1), 00229 /* z */ r*std::cos(theta) + this->center()(2)); 00230 }
Member Data Documentation
Point libMesh::Sphere::_cent [private] |
Real libMesh::Sphere::_rad [private] |
The documentation for this class was generated from the following files:
Site Created By: libMesh Developers
Last modified: February 05 2013 19:55:39 UTC
Hosted By:


