proj home

Files   Classes   Functions   Hierarchy  

trianglespace.h

Go to the documentation of this file.
00001 #ifndef TRIANGLESPACE_H
00002 #define TRIANGLESPACE_H
00003 
00004 #include <halfspaceD2.h>
00005 
00014 template< typename T, typename D >
00015 class trianglespace 
00016 {
00017 public:
00018 
00020   T pi[3];
00021 
00025   halfspaceD2< T, D > hi[3];
00026 
00028   trianglespace(T const & p0, T const & p1, T const & p2)
00029   {
00030     pi[0] = p0;
00031     pi[1] = p1;
00032     pi[2] = p2;
00033 
00034     hi[0].set(pi[2],pi[1]);
00035     hi[1].set(pi[0],pi[2]);
00036     hi[2].set(pi[1],pi[0]);
00037   }
00038 
00040   bool const isInside( T const & x ) const
00041   {
00042     if (hi[0].isInside(x))
00043       return true;
00044 
00045     if (hi[1].isInside(x))
00046       return true;
00047 
00048     if (hi[2].isInside(x))
00049       return true;
00050 
00051     return false;
00052   }
00053 
00054   bool const isOnEdge(T const & a, T const & b, T const & w, D const zero) const
00055   {
00056     assert( (b.dot()!=0) );
00057     D t = (w-a).dot(b);
00058     t /= b.dot();
00059     if (t<0)
00060        return false;
00061     if (t>1)
00062       return false;
00063 
00064     T p(a+b*t-w);
00065     D d = p.dot();
00066  
00067     if (d+zero<0)
00068       return false;
00069 
00070     if (d<zero)
00071       return true;
00072 
00073     return false;
00074   }
00075 
00076   bool const isOnBoundary(T const & x, D const zero ) const
00077   {
00078     if (isInside(x))
00079       return false;
00080 
00081     if (isOnEdge(pi[0],pi[1]-pi[0],x,zero))
00082       return true;
00083     
00084     if (isOnEdge(pi[0],pi[2]-pi[0],x,zero))
00085       return true;
00086 
00087     if (isOnEdge(pi[1],pi[2]-pi[1],x,zero))
00088       return true;
00089 
00090     return false;
00091   }
00092 };
00093 
00094 
00095 #endif
00096 
00097 

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