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();
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()
60 VectorD<D> &_access_center() {
63 void _set_radius(
double d) {
66 double &operator[](
unsigned int i) {
74 double operator[](
unsigned int i)
const {
84 unsigned int get_dimension()
const {
85 return center_.get_dimension();
95 return PI * 4.0 * get_squared(g.get_radius());
98 return PI * (4.0 / 3.0)
99 * std::pow(g.get_radius(), 3.0);
101 return BoundingBoxD<D>(g.get_center())
105 template <
unsigned int D>
107 return SphereD<D>(get_zero_vector_d<D>(), 1.0);
110 inline SphereD<-1> get_unit_sphere_kd(
unsigned int d) {
120 double d= (a.get_center()-b.get_center()).get_magnitude();
121 return d - a.get_radius() - b.get_radius();
131 double d= (a.get_center()-b.get_center()).get_squared_magnitude();
132 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< 3; ++i) {
143 double delta=std::abs(a.get_center()[i]- b.get_center()[i]);
144 if (delta >= sr)
return false;
150 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
154 struct SphereSpacesIO
156 const SphereD<D> &v_;
157 SphereSpacesIO(
const SphereD<D> &v): v_(v){}
160 inline std::ostream &operator<<(std::ostream &out, const SphereSpacesIO<D> &s)
162 for (
unsigned int i=0; i< s.v_.get_center().get_dimension(); ++i) {
163 out << s.v_.get_center()[i] <<
" ";
165 out << s.v_.get_radius();
176 inline internal::SphereSpacesIO<D> spaces_io(
const SphereD<D> &v) {
177 return internal::SphereSpacesIO<D>(v);
183 template <
class Geometry>
186 template <
class Geometry>
189 template <
class Geometry>
192 template <
class Geometry>
198 return s.get_center();
201 IMPALGEBRA_END_NAMESPACE