proj home

Files   Classes   Functions   Hierarchy  

halfspaceD3indexed.h

Go to the documentation of this file.
00001 #ifndef HALFSPACED3INDEXED_H
00002 #define HALFSPACED3INDEXED_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, typename INDX >
00019 class halfspaceD3indexed : public partitionspace<PT>
00020 {
00021 public:
00022 
00024   PT const & p0;  
00026   PT const & p1;
00028   PT const & p2;  
00030   PT normal;  
00031 
00033   INDX i0;
00035   INDX i1;
00037   INDX i2;
00038 
00042   halfspaceD3indexed
00043   (
00044     PT const * pts,
00045     INDX i0_,
00046     INDX i1_,
00047     INDX i2_
00048   )
00049     : p0(pts[i0_]), p1(pts[i1_]), p2(pts[i2_]),
00050       i0(i0_), i1(i1_), i2(i2_)
00051     { normalcalculate(); }
00052 
00054   void normalcalculate();
00055 
00057   boolc isInside( PT const & x ) const
00058     { return 0 < normal.x*(x.x-p0.x)+normal.y*(x.y-p0.y)+normal.z*(x.z-p0.z); }
00060   boolc isInsideOrOnBoundary( PT const & x ) const
00061     { return 0 < zero<PD>::val+normal.x*(x.x-p0.x)+normal.y*(x.y-p0.y)+normal.z*(x.z-p0.z); }
00062 
00066   PD const distancefromhalfspace(PT const & w) const
00067     { 
00068       PT p;
00069       p.x=normal.x*normal.x*(p0.x-w.x);
00070       p.y=normal.y*normal.y*(p0.y-w.y);
00071       p.z=normal.z*normal.z*(p0.z-w.z);
00072       return p.x*p.x+p.y*p.y+p.z*p.z;
00073     }
00074 };
00075 
00076 
00077 // --------------------------------------------------------- 
00078 // Implementation
00079 
00080 
00081 template< typename PT, typename PD, typename INDX >
00082 void halfspaceD3indexed<PT,PD,INDX>::normalcalculate()
00083 {
00084   PT u(p2 - p1);
00085   PT v(p0 - p1);
00086 
00087   normal.x=u.y*v.z-v.y*u.z;
00088   normal.y=u.z*v.x-u.x*v.z;
00089   normal.z=u.x*v.y-u.y*v.x;
00090 }
00091 
00092 
00093 #endif
00094 
00095 

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