• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List
  • File Members

/home/hauberg/Dokumenter/Capture/humim-tracker-0.1/src/OpenTissue/OpenTissue/collision/intersect/intersect_triangle_triangle_sat.h

Go to the documentation of this file.
00001 #ifndef OPENTISSUE_COLLISION_INTERSECT_INTERSECT_TRIANGLE_TRIANGLE_SAT_H
00002 #define OPENTISSUE_COLLISION_INTERSECT_INTERSECT_TRIANGLE_TRIANGLE_SAT_H
00003 //
00004 // OpenTissue Template Library
00005 // - A generic toolbox for physics-based modeling and simulation.
00006 // Copyright (C) 2008 Department of Computer Science, University of Copenhagen.
00007 //
00008 // OTTL is licensed under zlib: http://opensource.org/licenses/zlib-license.php
00009 //
00010 #include <OpenTissue/configuration.h>
00011 
00012 namespace OpenTissue
00013 {
00014   namespace intersect
00015   {
00016 
00017     template<typename vector3_type>
00018     bool triangle_triangle_sat(
00019       vector3_type const & a0
00020       , vector3_type const & a1
00021       , vector3_type const & a2
00022       , vector3_type const & b0
00023       , vector3_type const & b1
00024       , vector3_type const & b2        
00025       )
00026     {
00027       return !separation_triangle_triangle(a0,a1,a2,b0,b1,b2);
00028     }
00029 
00030 
00045     template<typename vector3_type>
00046     bool separation_triangle_triangle(
00047       vector3_type const & a0
00048       , vector3_type const & a1
00049       , vector3_type const & a2
00050       , vector3_type const & b0
00051       , vector3_type const & b1
00052       , vector3_type const & b2        
00053       )
00054     {
00055       typedef typename vector3_type::value_type        real_type;
00056 
00057       vector3_type a10 = a1 - a0;
00058       vector3_type a20 = a2 - a0;
00059       vector3_type na  = a10 % a20;
00060       //--- SAT face plane of A
00061       {
00062         real_type w = na*a0;            
00063         real_type d0 = na*b0 - w;
00064         real_type d1 = na*b1 - w;
00065         real_type d2 = na*b2 - w;
00066         if(d0 > 0 && d1 > 0 && d2 > 0)
00067           return true;
00068         if(d0 < 0 && d1 < 0 && d2 < 0)
00069           return true;
00070       }
00071       vector3_type b10 = b1 - b0;
00072       vector3_type b20 = b2 - b0;
00073       vector3_type nb  = b10 % b20;
00074       //--- SAT face plane of B
00075       {
00076         real_type w = nb*b0;            
00077         real_type d0 = nb*a0 - w;
00078         real_type d1 = nb*a1 - w;
00079         real_type d2 = nb*a2 - w;
00080         if(d0 > 0 && d1 > 0 && d2 > 0)
00081           return true;
00082         if(d0 < 0 && d1 < 0 && d2 < 0)
00083           return true;
00084       }
00085       vector3_type a21 = a2 - a1;
00086       vector3_type b21 = b2 - b1;
00087       //--- SAT: a10 crossed with all edges of B
00088       {
00089         vector3_type n  = a10 % b10;
00090         real_type w = n*a0;
00091         real_type d = n*a2 - w;
00092         real_type d0 = n*b0 - w;
00093         real_type d2 = n*b2 - w;
00094         if(d > 0 && d0 < 0  && d2 < 0 )
00095           return true;
00096         if(d < 0 && d0 > 0  && d2 > 0 )
00097           return true;
00098       }
00099       {
00100         vector3_type n  = a10 % b20;
00101         real_type w = n*a0;
00102         real_type d = n*a2 - w;
00103         real_type d0 = n*b0 - w;
00104         real_type d1 = n*b1 - w;
00105         if(d > 0 && d0 < 0  && d1 < 0 )
00106           return true;
00107         if(d < 0 && d0 > 0  && d1 > 0 )
00108           return true;
00109       }
00110       {
00111         vector3_type n  = a10 % b21;
00112         real_type w = n*a0;
00113         real_type d = n*a2 - w;
00114         real_type d2 = n*b2 - w;
00115         real_type d1 = n*b1 - w;
00116         if(d > 0 && d2 < 0  && d1 < 0 )
00117           return true;
00118         if(d < 0 && d2 > 0  && d1 > 0 )
00119           return true;
00120       }
00121       //--- SAT: a20 crossed with all edges of B
00122       {
00123         vector3_type n  = a20 % b10;
00124         real_type w = n*a0;
00125         real_type d = n*a1 - w;
00126         real_type d0 = n*b0 - w;
00127         real_type d2 = n*b2 - w;
00128         if(d > 0 && d0 < 0  && d2 < 0 )
00129           return true;
00130         if(d < 0 && d0 > 0  && d2 > 0 )
00131           return true;
00132       }
00133       {
00134         vector3_type n  = a20 % b20;
00135         real_type w = n*a0;
00136         real_type d = n*a1 - w;
00137         real_type d0 = n*b0 - w;
00138         real_type d1 = n*b1 - w;
00139         if(d > 0 && d0 < 0  && d1 < 0 )
00140           return true;
00141         if(d < 0 && d0 > 0  && d1 > 0 )
00142           return true;
00143       }
00144       {
00145         vector3_type n  = a20 % b21;
00146         real_type w = n*a0;
00147         real_type d = n*a1 - w;
00148         real_type d2 = n*b2 - w;
00149         real_type d1 = n*b1 - w;
00150         if(d > 0 && d2 < 0  && d1 < 0 )
00151           return true;
00152         if(d < 0 && d2 > 0  && d1 > 0 )
00153           return true;
00154       }
00155       //--- SAT: a21 crossed with all edges of B
00156       {
00157         vector3_type n  = a21 % b10;
00158         real_type w = n*a1;
00159         real_type d = n*a0 - w;
00160         real_type d0 = n*b0 - w;
00161         real_type d2 = n*b2 - w;
00162         if(d > 0 && d0 < 0  && d2 < 0 )
00163           return true;
00164         if(d < 0 && d0 > 0  && d2 > 0 )
00165           return true;
00166       }
00167       {
00168         vector3_type n  = a21 % b20;
00169         real_type w = n*a1;
00170         real_type d = n*a0 - w;
00171         real_type d0 = n*b0 - w;
00172         real_type d1 = n*b1 - w;
00173         if(d > 0 && d0 < 0  && d1 < 0 )
00174           return true;
00175         if(d < 0 && d0 > 0  && d1 > 0 )
00176           return true;
00177       }
00178       {
00179         vector3_type n  = a21 % b21;
00180         real_type w = n*a1;
00181         real_type d = n*a0 - w;
00182         real_type d2 = n*b2 - w;
00183         real_type d1 = n*b1 - w;
00184         if(d > 0 && d2 < 0  && d1 < 0 )
00185           return true;
00186         if(d < 0 && d2 > 0  && d1 > 0 )
00187           return true;
00188       }
00189       return false;
00190     }
00191 
00192   } //End of namespace intersect
00193 
00194 } //End of namespace OpenTissue
00195 
00196 // OPENTISSUE_COLLISION_INTERSECT_INTERSECT_TRIANGLE_TRIANGLE_SAT_H
00197 #endif

Generated on Thu Dec 1 2011 12:50:55 for HUMIM Tracker by  doxygen 1.7.1