00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef WFMATH_BALL_H
00027 #define WFMATH_BALL_H
00028
00029 #include <wfmath/const.h>
00030 #include <wfmath/vector.h>
00031 #include <wfmath/point.h>
00032 #include <wfmath/axisbox.h>
00033 #include <wfmath/intersect_decls.h>
00034
00035 namespace WFMath {
00036
00037 template<const int dim> class Ball;
00038
00039 #ifndef WFMATH_NO_TEMPLATES_AS_TEMPLATE_PARAMETERS
00040
00041 template<const int dim, template<class> class container>
00042 Ball<dim> BoundingSphere(const container<Point<dim> >& c);
00044 template<const int dim, template<class> class container>
00045 Ball<dim> BoundingSphereSloppy(const container<Point<dim> >& c);
00046 #endif
00047
00048 template<const int dim>
00049 std::ostream& operator<<(std::ostream& os, const Ball<dim>& m);
00050 template<const int dim>
00051 std::istream& operator>>(std::istream& is, Ball<dim>& m);
00052
00054
00064 template<const int dim>
00065 class Ball
00066 {
00067 public:
00069 Ball() {}
00071 Ball(const Point<dim>& center, CoordType radius)
00072 : m_center(center), m_radius(radius) {assert(radius >= 0);}
00074 Ball(const Ball& b) : m_center(b.m_center), m_radius(b.m_radius) {}
00075
00076 ~Ball() {}
00077
00078 friend std::ostream& operator<< <dim>(std::ostream& os, const Ball& b);
00079 friend std::istream& operator>> <dim>(std::istream& is, Ball& b);
00080
00081 Ball& operator=(const Ball& b)
00082 {m_radius = b.m_radius; m_center = b.m_center; return *this;}
00083
00084 bool isEqualTo(const Ball& b, double epsilon = WFMATH_EPSILON) const;
00085
00086 bool operator==(const Ball& b) const {return isEqualTo(b);}
00087 bool operator!=(const Ball& b) const {return !isEqualTo(b);}
00088
00089 bool isValid() const {return m_center.isValid();}
00090
00091 bool operator< (const Ball& b) const;
00092
00093
00094
00095 int numCorners() const {return 0;}
00096
00097
00098
00099
00100 Point<dim> getCorner(int i) const {assert(false);}
00101 Point<dim> getCenter() const {return m_center;}
00102
00104 const Point<dim>& center() const {return m_center;}
00106 Point<dim>& center() {return m_center;}
00108 CoordType radius() const {return m_radius;}
00110 CoordType& radius() {return m_radius;}
00111
00112
00113
00114 Ball& shift(const Vector<dim>& v) {m_center += v; return *this;}
00115 Ball& moveCornerTo(const Point<dim>& p, int corner) {assert(false);}
00116 Ball& moveCenterTo(const Point<dim>& p) {m_center = p; return *this;}
00117
00118 Ball& rotateCorner(const RotMatrix<dim>& m, int corner) {assert(false);}
00119 Ball& rotateCenter(const RotMatrix<dim>& m) {return *this;}
00120 Ball& rotatePoint(const RotMatrix<dim>& m, const Point<dim>& p)
00121 {m_center.rotate(m, p); return *this;}
00122
00123
00124
00125 AxisBox<dim> boundingBox() const;
00126 Ball boundingSphere() const {return *this;}
00127 Ball boundingSphereSloppy() const {return *this;}
00128
00129 friend bool Intersect<dim>(const Ball& b, const Point<dim>& p, bool proper);
00130 friend bool Contains<dim>(const Point<dim>& p, const Ball& b, bool proper);
00131
00132 friend bool Intersect<dim>(const Ball& b, const AxisBox<dim>& a, bool proper);
00133 friend bool Contains<dim>(const Ball& b, const AxisBox<dim>& a, bool proper);
00134 friend bool Contains<dim>(const AxisBox<dim>& a, const Ball& b, bool proper);
00135
00136 friend bool Intersect<dim>(const Ball& b1, const Ball& b2, bool proper);
00137 friend bool Contains<dim>(const Ball& outer, const Ball& inner, bool proper);
00138
00139 friend bool Intersect<dim>(const Segment<dim>& s, const Ball& b, bool proper);
00140 friend bool Contains<dim>(const Segment<dim>& s, const Ball& b, bool proper);
00141
00142 friend bool Intersect<dim>(const RotBox<dim>& r, const Ball& b, bool proper);
00143 friend bool Contains<dim>(const RotBox<dim>& r, const Ball& b, bool proper);
00144 friend bool Contains<dim>(const Ball& b, const RotBox<dim>& r, bool proper);
00145
00146 friend bool Intersect<dim>(const Polygon<dim>& p, const Ball& b, bool proper);
00147 friend bool Contains<dim>(const Polygon<dim>& p, const Ball& b, bool proper);
00148 friend bool Contains<dim>(const Ball& b, const Polygon<dim>& p, bool proper);
00149
00150 private:
00151
00152 Point<dim> m_center;
00153 CoordType m_radius;
00154 };
00155
00156 }
00157
00158 #include <wfmath/ball_funcs.h>
00159
00160 #endif // WFMATH_BALL_H