8 #ifndef IMPALGEBRA_SPHERE_D_H
9 #define IMPALGEBRA_SPHERE_D_H
17 #include <boost/serialization/access.hpp>
20 IMPALGEBRA_BEGIN_NAMESPACE
27 friend class boost::serialization::access;
29 template<
class Archive>
30 void serialize(Archive &ar,
const unsigned int) {
31 ar & center_ & radius_;
36 #if IMP_HAS_CHECKS >= IMP_USAGE
37 radius_ = std::numeric_limits<double>::quiet_NaN();
41 : center_(center), radius_(radius) {
44 double get_radius()
const {
46 "Attempt to use uninitialized sphere.");
49 const VectorD<D> &get_center()
const {
return center_; }
52 double d = (get_center() - o.get_center()).get_magnitude();
53 return (d + o.get_radius() < get_radius());
58 return ((p - center_).get_squared_magnitude() <= get_squared(radius_));
61 { out <<
"(" << spaces_io(center_) <<
": " << get_radius() <<
")"; });
62 #ifdef IMP_SWIG_WRAPPER
63 static void _get_struct_size(
size_t &sz,
size_t ¢er_offset,
64 size_t &radius_offset) {
65 sz =
sizeof(SphereD<D>);
66 center_offset = offsetof(SphereD<D>, center_);
67 radius_offset = offsetof(SphereD<D>, radius_);
72 VectorD<D> &_access_center() {
return center_; }
73 void _set_radius(
double d) { radius_ = d; }
74 void _set_center(
const VectorD<D> ¢er){ center_ = center; }
75 double &operator[](
unsigned int i) {
83 double operator[](
unsigned int i)
const {
93 unsigned int get_dimension()
const {
return center_.get_dimension(); }
101 {
return PI * 4.0 * get_squared(g.get_radius()); },
102 {
return PI * (4.0 / 3.0) * std::pow(g.get_radius(), 3.0); },
103 return BoundingBoxD<D>(g.get_center()) +
106 template <
unsigned int D>
108 return SphereD<D>(get_zero_vector_d<D>(), 1.0);
111 inline SphereD<-1> get_unit_sphere_kd(
unsigned int d) {
121 double d = (a.get_center() - b.get_center()).get_magnitude();
122 return d - a.get_radius() - b.get_radius();
132 double d = (a.get_center() - b.get_center()).get_squared_magnitude();
133 return d - square(a.get_radius()) - square(b.get_radius());
141 double sr = a.get_radius() + b.get_radius();
142 for (
unsigned int i = 0; i < a.get_dimension(); ++i) {
143 double delta = std::abs(a.get_center()[i] - b.get_center()[i]);
144 if (delta >= sr)
return false;
149 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
153 struct SphereSpacesIO {
154 const SphereD<D> &v_;
155 SphereSpacesIO(
const SphereD<D> &v) : v_(v) {}
158 inline std::ostream &operator<<(std::ostream &out, const SphereSpacesIO<D> &s) {
159 for (
unsigned int i = 0; i < s.v_.get_center().get_dimension(); ++i) {
160 out << s.v_.get_center()[i] <<
" ";
162 out << s.v_.get_radius();
173 inline internal::SphereSpacesIO<D> spaces_io(
const SphereD<D> &v) {
174 return internal::SphereSpacesIO<D>(v);
180 template <
class Geometry>
183 template <
class Geometry>
186 template <
class Geometry>
189 template <
class Geometry>
194 VectorD<D> get_vector_geometry(
const SphereD<D> &s) {
195 return s.get_center();
198 IMPALGEBRA_END_NAMESPACE
Base class for geometric types.
bool get_contains(const SphereD< D > &o) const
Return true if this sphere contains the other one.
#define IMP_SHOWABLE_INLINE(Name, how_to_show)
Declare the methods needed by an object that can be printed.
VectorD< D > get_zero_vector_kd(int Di)
Return a dynamically sized vector of zeros.
static const double PI
the constant pi
double get_volume(const Cone3D &g)
double get_squared_distance(const VectorD< D > &v1, const VectorD< D > &v2)
Compute the squared distance between two vectors.
#define IMP_INTERNAL_CHECK(expr, message)
An assertion to check for internal errors in IMP. An IMP::ErrorException will be thrown.
Base class for geometric types.
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 intersect.
BoundingBoxD< 3 > get_bounding_box(const Cone3D &g)
#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.
double get_surface_area(const Cone3D &g)
double get_area(const Plane3D &g)
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.
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
bool get_contains(const VectorD< D > &p) const
Return true if the point is in or on the surface of the sphere.
Represent a sphere in D-dimensions.
double get_power_distance(const SphereD< D > &a, const SphereD< D > &b)
Return the power distance between the two spheres.