proj home

Files   Classes   Functions   Hierarchy  

boxOBBhalfspaceD2< PT, PD > Class Template Reference

OBB and OBB intersection test. More...

#include <boxOBBhalfspaceD2.h>

Inheritance diagram for boxOBBhalfspaceD2< PT, PD >:
Collaboration diagram for boxOBBhalfspaceD2< PT, PD >:

List of all members.

Public Member Functions

 boxOBBhalfspaceD2 ()
 Unconstructed state.
 boxOBBhalfspaceD2 (PT const &_center, PT const &_arm1, PT const &_arm2, PD const _arm1len, PD const _arm2len)
 Construct a OBB.
template<typename W >
void construct (W const &p0, W const &p1, W const &p2, W const &p3)
 Construct a OBB from 4 anticlockwise points.
boolc intersects (PT const &p) const
 Is the point inside the box?
boolc intersects (boxOBBhalfspaceD2< PT, PD > &B2)
 Do the bounding boxes intersect?
boolc sees (boxOBBhalfspaceD2< PT, PD > &B2)
 Does this boxes half-spaces facing outwards see B2?
void cornerpoints (PT &p0, PT &p1, PT &p2, PT &p3) const
 Get this boxes corner points, from bottom left anti clockwise.
 operator stringc () const
 Serialize this object by writing it out as a string.

Public Attributes

PT center
 The centroid.
PT arm1
 The arm is a unit vector.
PT arm2
 The arm is a unit vector.
PD arm1len
 Half the length of the box in arm1 direction.
PD arm2len
 Half the length of the box in arm2 direction.

Static Public Attributes

static PT qi [4]
 Exposed points for visualization (Testing) and reuse.
static PT pi [5]
 Exposed points for visualization (Testing) and reuse.


Detailed Description

template<typename PT, typename PD>
class boxOBBhalfspaceD2< PT, PD >

OBB and OBB intersection test.

Also a point inside OBB test too.

Arm 1 and 2 are perpendicular unit vectors.

Definition at line 19 of file boxOBBhalfspaceD2.h.


Constructor & Destructor Documentation

template<typename PT, typename PD>
boxOBBhalfspaceD2< PT, PD >::boxOBBhalfspaceD2 (  )  [inline]

Unconstructed state.

Definition at line 41 of file boxOBBhalfspaceD2.h.

00042     {}

template<typename PT, typename PD>
boxOBBhalfspaceD2< PT, PD >::boxOBBhalfspaceD2 ( PT const &  _center,
PT const &  _arm1,
PT const &  _arm2,
PD const   _arm1len,
PD const   _arm2len 
) [inline]

Construct a OBB.

Definition at line 141 of file boxOBBhalfspaceD2.h.

00148   : center(_center), arm1(_arm1), arm2(_arm2), arm1len(_arm1len),
00149   arm2len(_arm2len)
00150 {
00151   assert( zero<PD>::test(arm1.dot(arm2)) == true );
00152   assert( zero<PD>::test(arm1.dot())==false );
00153   assert( zero<PD>::test(arm2.dot())==false );
00154   assert( zero<PD>::test(arm1.dot()-1.0)==true );
00155   assert( zero<PD>::test(arm2.dot()-1.0)==true );
00156 }


Member Function Documentation

template<typename PT , typename PD >
template<typename W >
void boxOBBhalfspaceD2< PT, PD >::construct ( W const &  p0,
W const &  p1,
W const &  p2,
W const &  p3 
) [inline]

Construct a OBB from 4 anticlockwise points.

Definition at line 121 of file boxOBBhalfspaceD2.h.

Referenced by boxOBBhalfspaceD2test::unittest01(), and boxOBBhalfspaceD2test::unittest02().

00127 {
00128   center = ((p0+p1+p2+p3)*0.25);
00129   arm1 = (p1-p0);
00130   arm1.normalize();
00131   arm2 = (p3-p0);
00132   arm2.normalize();
00133   arm1len = (p0-p1).distance()*0.5;
00134   arm2len = (p0-p3).distance()*0.5;
00135 
00136   assert( zero<PD>::test((p0+arm1*arm1len*2.0+arm2*arm2len*2.0-p2).dot())==true );
00137 }

template<typename PT, typename PD >
void boxOBBhalfspaceD2< PT, PD >::cornerpoints ( PT &  p0,
PT &  p1,
PT &  p2,
PT &  p3 
) const [inline]

Get this boxes corner points, from bottom left anti clockwise.

Definition at line 105 of file boxOBBhalfspaceD2.h.

Referenced by circleD2< PT, PD >::intersects(), boxOBBhalfspaceD2< PT, PD >::sees(), boxOBBhalfspaceD2test::unittest01(), circleD2test::update01(), and boxOBBhalfspaceD2test::update01().

00111 {
00112   p0 = center - arm1*arm1len - arm2*arm2len;
00113   p1 = center + arm1*arm1len - arm2*arm2len;
00114   p2 = center + arm1*arm1len + arm2*arm2len;
00115   p3 = center - arm1*arm1len + arm2*arm2len;
00116 }

template<typename PT, typename PD>
boolc boxOBBhalfspaceD2< PT, PD >::intersects ( boxOBBhalfspaceD2< PT, PD > &  B2  )  [inline]

Do the bounding boxes intersect?

Definition at line 160 of file boxOBBhalfspaceD2.h.

References boxOBBhalfspaceD2< PT, PD >::sees().

00163 {
00164   if (sees(B2)==false)
00165     return true;
00166 
00167   return ! B2.sees(*this);
00168 }

template<typename PT, typename PD >
boolc boxOBBhalfspaceD2< PT, PD >::intersects ( PT const &  p  )  const [inline]

Is the point inside the box?

Definition at line 228 of file boxOBBhalfspaceD2.h.

References boxOBBhalfspaceD2< PT, PD >::arm1, boxOBBhalfspaceD2< PT, PD >::arm1len, boxOBBhalfspaceD2< PT, PD >::arm2, boxOBBhalfspaceD2< PT, PD >::arm2len, and boxOBBhalfspaceD2< PT, PD >::center.

Referenced by boxOBBhalfspaceD2test::unittest02(), and boxOBBhalfspaceD2test::update01().

00229 {
00230   //if ((p-(center+arm1*arm1len)).dot(arm1) > (PD)0)
00231   if ((p-(center+arm1*arm1len)).dot(arm1) > zero<PD>::val)
00232     return false;
00233   //if ((p-(center-arm1*arm1len)).dot(arm1) < (PD)0)
00234   if (((center-arm1*arm1len)-p).dot(arm1) > zero<PD>::val)
00235     return false;
00236 
00237   //if ((p-(center+arm2*arm2len)).dot(arm2) > (PD)0)
00238   if ((p-(center+arm2*arm2len)).dot(arm2) > zero<PD>::val)
00239     return false;
00240   //if ((p-(center-arm2*arm2len)).dot(arm2) < (PD)0)
00241   if (((center-arm2*arm2len)-p).dot(arm2) > zero<PD>::val)
00242     return false;
00243 
00244   return true;
00245 }

template<typename PT , typename PD >
boxOBBhalfspaceD2< PT, PD >::operator stringc (  )  const [inline]

Serialize this object by writing it out as a string.

Definition at line 92 of file boxOBBhalfspaceD2.h.

References boxOBBhalfspaceD2< PT, PD >::arm1, boxOBBhalfspaceD2< PT, PD >::arm1len, boxOBBhalfspaceD2< PT, PD >::arm2, boxOBBhalfspaceD2< PT, PD >::arm2len, and boxOBBhalfspaceD2< PT, PD >::center.

00093 {
00094   stringstream ss;  
00095 
00096   ss << center << "  " << arm1 << "  " << arm2 << "  ";
00097   ss << arm1len << "  " << arm2len;
00098 
00099   return ss.str();
00100 }

template<typename PT, typename PD>
boolc boxOBBhalfspaceD2< PT, PD >::sees ( boxOBBhalfspaceD2< PT, PD > &  B2  )  [inline]

Does this boxes half-spaces facing outwards see B2?

Definition at line 172 of file boxOBBhalfspaceD2.h.

References boxOBBhalfspaceD2< PT, PD >::center, and boxOBBhalfspaceD2< PT, PD >::cornerpoints().

Referenced by boxOBBhalfspaceD2< PT, PD >::intersects().

00175 {
00176   B2.cornerpoints(pi[0],pi[1],pi[2],pi[3]);
00177 
00178 //cout << SHOW(arm1) << endl;
00179 //cout << SHOW(arm2) << endl;
00180 //cout << SHOW(arm1len) << endl;
00181 //cout << SHOW(arm2len) << endl;
00182 
00183   //static point2<double> qi[4];
00184   qi[0] = center + arm1*(arm1len);
00185   qi[1] = center + arm1*(-arm1len);
00186   qi[2] = center + arm2*(arm2len);
00187   qi[3] = center + arm2*(-arm2len);
00188 
00189   pi[4] = B2.center;
00190 
00191 //cout << SHOW(center) << endl;
00192 //cout << SHOW(qi[2]) << endl;
00193 
00194   uint count=0;
00195   for (uint k=0; k<5; ++k)
00196   {
00197 //cout << SHOW(k) << endl;
00198 //cout << SHOW((pi[k]-qi[0]).dot(arm1)>0.0) << endl;
00199     if ((pi[k]-qi[0]).dot(arm1)>0.0)
00200     {
00201       ++count;
00202       continue;
00203     }
00204 //cout << SHOW((pi[k]-qi[1]).dot(arm1)<0.0) << endl;
00205     if ((pi[k]-qi[1]).dot(arm1)<0.0)
00206     {
00207       ++count;
00208       continue;
00209     }
00210 //cout << SHOW((pi[k]-qi[2]).dot(arm2)>0.0) << endl;
00211     if ((pi[k]-qi[2]).dot(arm2)>0.0)
00212     {
00213       ++count;
00214       continue;
00215     }
00216 //cout << SHOW((pi[k]-qi[3]).dot(arm2)<0.0) << endl;
00217     if ((pi[k]-qi[3]).dot(arm2)<0.0)
00218     {
00219       ++count;
00220     }
00221   }
00222 //cout << SHOW(count) << endl;
00223 
00224   return (count==5);
00225 }


Member Data Documentation

template<typename PT, typename PD>
PT boxOBBhalfspaceD2< PT, PD >::arm1

template<typename PT, typename PD>
PD boxOBBhalfspaceD2< PT, PD >::arm1len

Half the length of the box in arm1 direction.

Definition at line 30 of file boxOBBhalfspaceD2.h.

Referenced by boxOBBhalfspaceD2< PT, PD >::intersects(), and boxOBBhalfspaceD2< PT, PD >::operator stringc().

template<typename PT, typename PD>
PT boxOBBhalfspaceD2< PT, PD >::arm2

template<typename PT, typename PD>
PD boxOBBhalfspaceD2< PT, PD >::arm2len

Half the length of the box in arm2 direction.

Definition at line 32 of file boxOBBhalfspaceD2.h.

Referenced by boxOBBhalfspaceD2< PT, PD >::intersects(), and boxOBBhalfspaceD2< PT, PD >::operator stringc().

template<typename PT, typename PD>
PT boxOBBhalfspaceD2< PT, PD >::center

template<typename PT, typename PD>
PT boxOBBhalfspaceD2< PT, PD >::pi [inline, static]

Exposed points for visualization (Testing) and reuse.

Definition at line 37 of file boxOBBhalfspaceD2.h.

template<typename PT, typename PD>
PT boxOBBhalfspaceD2< PT, PD >::qi [inline, static]

Exposed points for visualization (Testing) and reuse.

Definition at line 35 of file boxOBBhalfspaceD2.h.

Referenced by boxOBBhalfspaceD2test::update01().


The documentation for this class was generated from the following file:

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