proj home

Files   Classes   Functions   Hierarchy  

halfspaceD3.h

Go to the documentation of this file.
00001 #ifndef D3HALFSPACE_H
00002 #define D3HALFSPACE_H
00003 
00004 #include <cassert>
00005 using namespace std;
00006 
00007 #include <typedefs.h>
00008 #include <partitionspace.h>
00009 #include <mathlib.h>
00010 #include <zero.h>
00011 
00018 template< typename PT, typename PD >
00019 class halfspaceD3 : public partitionspace<PT>
00020 {
00021 public:
00022 
00024   PT p0;  
00026   PT p1;
00028   PT p2;  
00030   PT normal;  
00031 
00033   halfspaceD3() {}
00034 
00035   template< typename INDX >
00036   halfspaceD3
00037   (
00038     PT const * pts,
00039     INDX i0,
00040     INDX i1,
00041     INDX i2
00042   )
00043     : p0(pts[i0]), p1(pts[i1]), p2(pts[i2])
00044     { normalcalculate(); }
00045 
00049   halfspaceD3
00050   ( 
00051     PT const & p0_,
00052     PT const & p1_,
00053     PT const & p2_
00054   );
00056   void set
00057   ( 
00058     PT const & p0_,
00059     PT const & p1_,
00060     PT const & p2_
00061   );
00062 
00064   void normalcalculate();
00065 
00067   boolc isInside( PT const & x ) const
00068     { return 0 < normal.x*(x.x-p0.x)+normal.y*(x.y-p0.y)+normal.z*(x.z-p0.z); }
00070   boolc isInsideOrOnBoundary( PT const & x ) const
00071     { return 0 < zero<PD>::val+normal.x*(x.x-p0.x)+normal.y*(x.y-p0.y)+normal.z*(x.z-p0.z); }
00072     //{ return 0 < zero+normal.x*(x.x-p0.x)+normal.y*(x.y-p0.y)+normal.z*(x.z-p0.z); }
00073 
00074 
00075 /*
00076 // <TODO> Remove crossproduct.  Check what and where this func works.
00077   // Calculate the area of the triangle a,b,c.
00078   T const trianglearea() const
00079   {
00080     T c;
00081     c.crossproduct(p1-p0,p2-p0);
00082 //cout << SHOW(c) << endl;
00083 
00084     return c.distance()*.5;
00085   }
00086 */
00087 
00091   PD const distancefromhalfspace(PT const & w) const
00092     { 
00093       PT p;
00094       p.x=normal.x*normal.x*(p0.x-w.x);
00095       p.y=normal.y*normal.y*(p0.y-w.y);
00096       p.z=normal.z*normal.z*(p0.z-w.z);
00097       return p.x*p.x+p.y*p.y+p.z*p.z;
00098 /*
00099       return normal.x*normal.x*(p0.x-w.x)+
00100              normal.y*normal.y*(p0.y-w.y)+
00101              normal.z*normal.z*(p0.z-w.z);
00102 */
00103     }
00104 
00105 
00106 };
00107 
00108 
00109 // --------------------------------------------------------- 
00110 // Implementation
00111 
00112 
00113 /*
00114   template< typename INDX >
00115   halfspaceD3
00116   (
00117     PT const * pts,
00118     INDX i0,
00119     INDX i1,
00120     INDX i2
00121   );
00122 */
00123 
00124 template< typename PT, typename PD >
00125 void halfspaceD3<PT,PD>::normalcalculate()
00126 {
00127   PT u(p2 - p1);
00128   PT v(p0 - p1);
00129 
00130   normal.x=u.y*v.z-v.y*u.z;
00131   normal.y=u.z*v.x-u.x*v.z;
00132   normal.z=u.x*v.y-u.y*v.x;
00133 }
00134 
00135 template< typename PT, typename PD >
00136 halfspaceD3<PT,PD>::halfspaceD3
00137 (
00138   PT const & p0_,
00139   PT const & p1_,
00140   PT const & p2_
00141 )
00142   : p0(p0_), p1(p1_), p2(p2_)
00143 {
00144   normalcalculate();
00145 }
00146 
00147 template< typename PT, typename PD >
00148 void halfspaceD3<PT,PD>::set
00149 (
00150   PT const & p0_,
00151   PT const & p1_,
00152   PT const & p2_
00153 )
00154 {
00155   p0=p0_;
00156   p1=p1_;
00157   p2=p2_;
00158 
00159   normalcalculate();
00160 }
00161 
00162 
00163 #endif
00164 
00165 

Generated on Fri Mar 4 00:49:28 2011 for Chelton Evans Source by  doxygen 1.5.8