Files Classes Functions Hierarchy
00001 #ifndef CIRCLED2_H 00002 #define CIRCLED2_H 00003 00004 #include <boxOBBhalfspaceD2.h> 00005 #include <line.h> 00006 00007 00011 template< typename PT, typename PD > 00012 class circleD2 00013 { 00014 public: 00015 00017 PT center; 00019 PD radius; 00020 00022 circleD2 00023 ( 00024 PT const & center_, 00025 PD const radius_ 00026 ) 00027 : center(center_), radius(radius_) {} 00028 00030 boolc intersects( boxOBBhalfspaceD2<PT,PD> & B ); 00031 }; 00032 00033 //--------------------------------------------------------- 00034 // Implementation 00035 00036 template< typename PT, typename PD > 00037 boolc circleD2<PT,PD>::intersects( boxOBBhalfspaceD2<PT,PD> & B ) 00038 { 00039 PT pi[4]; 00040 B.cornerpoints(pi[0],pi[1],pi[2],pi[3]); 00041 00042 PD t; 00043 00044 bool inside=true; 00045 for (uint i=0; i<4; ++i) 00046 { 00047 line<PT,PD> L(pi[(i+1)%4],pi[i],true); 00048 PT normal(-L.nml.y,L.nml.x); 00049 if (normal.dot(center-L.pos)>=0.0) 00050 { 00051 inside=false; 00052 00053 L.nearestpointcapped(t,center); 00054 if ((L(t)-center).dot()<=radius*radius) 00055 return true; 00056 } 00057 } 00058 00059 return inside; 00060 } 00061 00062 00063 #endif 00064 00065
1.5.8