8 #ifndef IMPALGEBRA_SPHERE_D_H
9 #define IMPALGEBRA_SPHERE_D_H
19 IMPALGEBRA_BEGIN_NAMESPACE
28 #if IMP_HAS_CHECKS >= IMP_USAGE
29 radius_ = std::numeric_limits<double>::quiet_NaN();
33 : center_(center), radius_(radius) {
36 double get_radius()
const {
38 "Attempt to use uninitialized sphere.");
41 const VectorD<D> &get_center()
const {
return center_; }
44 double d = (get_center() - o.get_center()).get_magnitude();
45 return (d + o.get_radius() < get_radius());
52 return ((p - center_).get_squared_magnitude() <= get_squared(radius_));
55 { out <<
"(" << spaces_io(center_) <<
": " << get_radius() <<
")"; });
58 VectorD<D> &_access_center() {
return center_; }
59 void _set_radius(
double d) { radius_ = d; }
60 double &operator[](
unsigned int i) {
68 double operator[](
unsigned int i)
const {
78 unsigned int get_dimension()
const {
return center_.get_dimension(); }
86 {
return PI * 4.0 * get_squared(g.get_radius()); },
87 {
return PI * (4.0 / 3.0) * std::pow(g.get_radius(), 3.0); },
88 return BoundingBoxD<D>(g.get_center()) +
91 template <
unsigned int D>
93 return SphereD<D>(get_zero_vector_d<D>(), 1.0);
96 inline SphereD<-1> get_unit_sphere_kd(
unsigned int d) {
106 double d = (a.get_center() - b.get_center()).get_magnitude();
107 return d - a.get_radius() - b.get_radius();
117 double d = (a.get_center() - b.get_center()).get_squared_magnitude();
118 return d - square(a.get_radius()) - square(b.get_radius());
126 double sr = a.get_radius() + b.get_radius();
127 for (
unsigned int i = 0; i < 3; ++i) {
128 double delta = std::abs(a.get_center()[i] - b.get_center()[i]);
129 if (delta >= sr)
return false;
134 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
138 struct SphereSpacesIO {
139 const SphereD<D> &v_;
140 SphereSpacesIO(
const SphereD<D> &v) : v_(v) {}
143 inline std::ostream &operator<<(std::ostream &out, const SphereSpacesIO<D> &s) {
144 for (
unsigned int i = 0; i < s.v_.get_center().get_dimension(); ++i) {
145 out << s.v_.get_center()[i] <<
" ";
147 out << s.v_.get_radius();
158 inline internal::SphereSpacesIO<D> spaces_io(
const SphereD<D> &v) {
159 return internal::SphereSpacesIO<D>(v);
165 template <
class Geometry>
168 template <
class Geometry>
171 template <
class Geometry>
174 template <
class Geometry>
179 VectorD<D> get_vector_geometry(
const SphereD<D> &s) {
180 return s.get_center();
183 IMPALGEBRA_END_NAMESPACE
bool get_contains(const SphereD< D > &o) const
Return true if this sphere contains the other one.
BoundingBoxD< 3 > get_bounding_box(const Geometry &)
Compute the bounding box of any geometric object.
VectorD< D > get_zero_vector_kd(int Di)
Return a dynamically sized vector of zeros.
static const double PI
the constant pi
double get_area(const Geometry &)
Compute the area of any surface object.
#define IMP_SHOWABLE_INLINE(Name, how_to_show)
Declare the methods needed by an object that can be printed.
double get_squared_distance(const VectorD< D > &v1, const VectorD< D > &v2)
compute the squared distance between two vectors
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
Functions to deal with very common math operations.
A Cartesian vector in D-dimensions.
bool get_interiors_intersect(const SphereD< D > &a, const SphereD< D > &b)
Return true if the two balls bounded by the two spheres interesect.
#define IMP_VOLUME_GEOMETRY_METHODS_D(Name, name, area, volume, bounding_box)
implement the needed namespace methods for a geometry type
A bounding box in D dimensions.
Various useful constants.
bool isnan(const T &a)
Return true if a number is NaN.
double get_distance(const SphereD< D > &a, const SphereD< D > &b)
Return the distance between the two spheres if they are disjoint.
bool get_contains(const VectorD< D > &p) const
Return true if the point is in or on the surface of the sphere.
double get_surface_area(const Geometry &)
Compute the surface area of any volumetric object.
Various important macros for implementing geometry.
double get_volume(const Geometry &)
Compute the volume of any volumetric object.
double get_power_distance(const SphereD< D > &a, const SphereD< D > &b)
Return the power distance between the two spheres.