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_ROT_BOX_H
00027 #define WFMATH_ROT_BOX_H
00028
00029 #include <wfmath/const.h>
00030 #include <wfmath/vector.h>
00031 #include <wfmath/point.h>
00032 #include <wfmath/rotmatrix.h>
00033 #include <wfmath/axisbox.h>
00034 #include <wfmath/ball.h>
00035 #include <wfmath/intersect_decls.h>
00036
00037 namespace WFMath {
00038
00039 template<const int dim> class RotBox;
00040
00041 template<const int dim>
00042 std::ostream& operator<<(std::ostream& os, const RotBox<dim>& r);
00043 template<const int dim>
00044 std::istream& operator>>(std::istream& is, RotBox<dim>& r);
00045
00047
00051 template<const int dim>
00052 class RotBox
00053 {
00054 public:
00056 RotBox() {}
00058
00063 RotBox(const Point<dim>& p, const Vector<dim>& size,
00064 const RotMatrix<dim>& orientation) : m_corner0(p), m_size(size),
00065 m_orient(orientation) {}
00067 RotBox(const RotBox& b) : m_corner0(b.m_corner0), m_size(b.m_size),
00068 m_orient(b.m_orient) {}
00069
00070 ~RotBox() {}
00071
00072 friend std::ostream& operator<< <dim>(std::ostream& os, const RotBox& r);
00073 friend std::istream& operator>> <dim>(std::istream& is, RotBox& r);
00074
00075 RotBox& operator=(const RotBox& s);
00076
00077 bool isEqualTo(const RotBox& b, double epsilon = WFMATH_EPSILON) const;
00078
00079 bool operator==(const RotBox& b) const {return isEqualTo(b);}
00080 bool operator!=(const RotBox& b) const {return !isEqualTo(b);}
00081
00082 bool isValid() const {return m_corner0.isValid() && m_size.isValid()
00083 && m_orient.isValid();}
00084
00085 bool operator< (const RotBox& b) const;
00086
00087
00088
00089 int numCorners() const {return 1 << dim;}
00090 Point<dim> getCorner(int i) const;
00091 Point<dim> getCenter() const {return m_corner0 + Prod(m_size / 2, m_orient);}
00092
00094 const Point<dim>& corner0() const {return m_corner0;}
00096 Point<dim>& corner0() {return m_corner0;}
00098 const Vector<dim>& size() const {return m_size;}
00100 Vector<dim>& size() {return m_size;}
00102 const RotMatrix<dim>& orientation() const {return m_orient;}
00104 RotMatrix<dim>& orientation() {return m_orient;}
00105
00106
00107
00108 RotBox& shift(const Vector<dim>& v)
00109 {m_corner0 += v; return *this;}
00110 RotBox& moveCornerTo(const Point<dim>& p, int corner)
00111 {return shift(p - getCorner(corner));}
00112 RotBox& moveCenterTo(const Point<dim>& p)
00113 {return shift(p - getCenter());}
00114
00115 RotBox& rotateCorner(const RotMatrix<dim>& m, int corner)
00116 {rotatePoint(m, getCorner(corner)); return *this;}
00117 RotBox& rotateCenter(const RotMatrix<dim>& m)
00118 {rotatePoint(m, getCenter()); return *this;}
00119 RotBox& rotatePoint(const RotMatrix<dim>& m, const Point<dim>& p)
00120 {m_orient = Prod(m_orient, m); m_corner0.rotate(m, p); return *this;}
00121
00122
00123
00124 AxisBox<dim> boundingBox() const;
00125 Ball<dim> boundingSphere() const
00126 {return Ball<dim>(getCenter(), m_size.mag() / 2);}
00127 Ball<dim> boundingSphereSloppy() const
00128 {return Ball<dim>(getCenter(), m_size.sqrMag() / 2);}
00129
00130 friend bool Intersect<dim>(const RotBox& r, const Point<dim>& p, bool proper);
00131 friend bool Contains<dim>(const Point<dim>& p, const RotBox& r, bool proper);
00132
00133 friend bool Intersect<dim>(const RotBox& r, const AxisBox<dim>& b, bool proper);
00134 friend bool Contains<dim>(const RotBox& r, const AxisBox<dim>& b, bool proper);
00135 friend bool Contains<dim>(const AxisBox<dim>& b, const RotBox& r, bool proper);
00136
00137 friend bool Intersect<dim>(const RotBox& r, const Ball<dim>& b, bool proper);
00138 friend bool Contains<dim>(const RotBox& r, const Ball<dim>& b, bool proper);
00139 friend bool Contains<dim>(const Ball<dim>& b, const RotBox& r, bool proper);
00140
00141 friend bool Intersect<dim>(const RotBox& r, const Segment<dim>& s, bool proper);
00142 friend bool Contains<dim>(const RotBox& r, const Segment<dim>& s, bool proper);
00143 friend bool Contains<dim>(const Segment<dim>& s, const RotBox& r, bool proper);
00144
00145 friend bool Intersect<dim>(const RotBox& r1, const RotBox& r2, bool proper);
00146 friend bool Contains<dim>(const RotBox& outer, const RotBox& inner, bool proper);
00147
00148 friend bool Intersect<dim>(const Polygon<dim>& p, const RotBox& r, bool proper);
00149 friend bool Contains<dim>(const Polygon<dim>& p, const RotBox& r, bool proper);
00150 friend bool Contains<dim>(const RotBox& r, const Polygon<dim>& p, bool proper);
00151
00152 private:
00153
00154 Point<dim> m_corner0;
00155 Vector<dim> m_size;
00156 RotMatrix<dim> m_orient;
00157 };
00158
00159 }
00160
00161 #include <wfmath/rotbox_funcs.h>
00162
00163 #endif // WFMATH_ROT_BOX_H