proj home

Files   Classes   Functions   Hierarchy  

halfspaceD2< PT, PD > Class Template Reference

Define a 2D half space with two ordered points. The half space points to the left of the directed line(p0,p1). More...

#include <halfspaceD2.h>

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

List of all members.

Public Member Functions

 halfspaceD2 ()
 Construct in uninitialized state.
 halfspaceD2 (PT const &p0_, PT const &p1_)
 Construct a half space from the ordered points.
void set (PT const &p0_, PT const &p1_)
 Construct a half space from the ordered points.
void normalcalculate ()
 Calculate the normal the ordered points.
boolc isInside (PT const &x) const
 Is the point inside the half space?
boolc isInsideOrOnBoundary (PT const &x) const
 Is the point on or inside the half space?
template<typename U >
void pointOnLine (PT &x, U const t) const
 Line [p0,p1] for t=[0,1].
boolc intersectionIn_t (PT &t, PT const &a, PT const &b) const
 Solve (t.x,t.y) : a+(-a+b)t.x = pointOnLine(t.y).
boolc intersection (PT &p, PT const &a, PT const &b) const
 Find the intersection of the line through (a,b) and this line.
boolc isOnBoundary (PT const &w) const
 The client configures zero for the isOnBoundary routine.
boolc clip (PD &t0, PD &t1, PT const &a, PT const &m) const
 Clip the line segment if cutting the half-space.
boolc clipNeg (PD &t0, PD &t1, PT const &a, PT const &m) const
 Invert the clip.
void minimizepointtoline (PD &t, PT const &w) const
 Find the nearest point on the line to w.
PD const distancefromhalfspace (PT const &w) const
 A measure of the minimum distance from the line to the point w without a square root.
 operator stringc () const
 Serialize this object by writing it out as a string.
stringc print () const
 For debug print this object.

Public Attributes

PT p0
 Start point.
PT p1
 End point.
PT normal
 Normal but not normalized.


Detailed Description

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

Define a 2D half space with two ordered points. The half space points to the left of the directed line(p0,p1).

<TODO> Rewrite half-space storing only one point p0 and the normal.

Need to define zero. eg

template<>
double zero<double>::val = 1E-15;

Definition at line 27 of file halfspaceD2.h.


Constructor & Destructor Documentation

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

Construct in uninitialized state.

Definition at line 39 of file halfspaceD2.h.

00039 {}

template<typename PT, typename PD>
halfspaceD2< PT, PD >::halfspaceD2 ( PT const &  p0_,
PT const &  p1_ 
) [inline]

Construct a half space from the ordered points.

The normal is the line rotated 90 degrees anti clockwise.

Definition at line 44 of file halfspaceD2.h.

00045     { set(p0_,p1_); }


Member Function Documentation

template<typename PT, typename PD>
boolc halfspaceD2< PT, PD >::clip ( PD &  t0,
PD &  t1,
PT const &  a,
PT const &  m 
) const [inline]

Clip the line segment if cutting the half-space.

A false result rejects the line as it is outside the half-space. Line a+m*t with [t0,t1].

Definition at line 250 of file halfspaceD2.h.

Referenced by halfspaceD2test::unittest01().

00256 {
00257   int k=0;
00258   if (isInside(a+m*t0))
00259     k += 1;
00260   if (isInside(a+m*t1))
00261     k += 2;
00262 
00263   switch (k)
00264   {
00265     case 0: return false;
00266     case 1: 
00267     {
00268       point2<PD> t;
00269       if ( solver<PD>::d2linearequ(t,m,p0-p1,p0-a) == false )
00270         return isInside(a);
00271       t1=t[0];
00272       break;
00273     }   
00274     case 2:
00275     {
00276       point2<PD> t;
00277       if ( solver<PD>::d2linearequ(t,m,p0-p1,p0-a) == false )
00278         return isInside(a);
00279       t0=t[0];
00280       break;
00281     }
00282     case 3: return true;
00283   }
00284 
00285   return true;
00286 }

template<typename PT, typename PD>
boolc halfspaceD2< PT, PD >::clipNeg ( PD &  t0,
PD &  t1,
PT const &  a,
PT const &  m 
) const [inline]

Invert the clip.

Definition at line 208 of file halfspaceD2.h.

Referenced by halfspaceD2test::unittest01().

00214 {
00215 
00216   int k=0;
00217   if (!isInside(a+m*t0))
00218     k += 1;
00219   if (!isInside(a+m*t1))
00220     k += 2;
00221 
00222   switch (k)
00223   {
00224     case 0: return false;
00225     case 1: 
00226     {
00227       point2<PD> t;
00228       if ( solver<PD>::d2linearequ(t,m,p0-p1,p0-a) == false )
00229         return !isInside(a);
00230       t1=t[0];
00231       break;
00232     }   
00233     case 2:
00234     {
00235       point2<PD> t;
00236       if ( solver<PD>::d2linearequ(t,m,p0-p1,p0-a) == false )
00237         return !isInside(a);
00238       t0=t[0];
00239       break;
00240     }
00241     case 3: return true;
00242   }
00243 
00244   return true;
00245 }

template<typename PT, typename PD >
PD const halfspaceD2< PT, PD >::distancefromhalfspace ( PT const &  w  )  const [inline]

A measure of the minimum distance from the line to the point w without a square root.

Definition at line 148 of file halfspaceD2.h.

References halfspaceD2< PT, PD >::minimizepointtoline(), and halfspaceD2< PT, PD >::pointOnLine().

Referenced by halfspaceD2test::test02().

00149 { 
00150   PD t;  
00151   minimizepointtoline(t,w); 
00152   PT w2; 
00153   pointOnLine(w2,t); 
00154   PT w3(w2.x-w.x,w2.y-w.y);
00155   return w3.x*w3.x+w3.y*w3.y;
00156 }

template<typename PT, typename PD >
boolc halfspaceD2< PT, PD >::intersection ( PT &  p,
PT const &  a,
PT const &  b 
) const [inline, virtual]

Find the intersection of the line through (a,b) and this line.

Reimplemented from partitionspace< PT >.

Definition at line 170 of file halfspaceD2.h.

References d2matsolve().

Referenced by bsptreeD2dispregions01< PT, PD, INDX >::update().

00175 {
00176   PT const u(b-a);
00177   PT const v(p0-p1);
00178   PT const w(p0-a);
00179   // t0*u+t1*v=w
00180   PT t;
00181   bool res = d2matsolve(t,u,v,w);
00182   if (res==false)
00183     return false;
00184 
00185   pointOnLine(p,t.y);
00186 
00187   return true;
00188 }

template<typename PT, typename PD >
boolc halfspaceD2< PT, PD >::intersectionIn_t ( PT &  t,
PT const &  a,
PT const &  b 
) const [inline]

Solve (t.x,t.y) : a+(-a+b)t.x = pointOnLine(t.y).

Definition at line 192 of file halfspaceD2.h.

References d2matsolve().

00197 {
00198   PT const u(b-a);
00199   PT const v(p0-p1);
00200   PT const w(p0-a);
00201   // t0*u+t1*v=w
00202 
00203   return d2matsolve(t,u,v,w);
00204 }

template<typename PT, typename PD>
boolc halfspaceD2< PT, PD >::isInside ( PT const &  x  )  const [inline, virtual]

Is the point inside the half space?

Implements partitionspace< PT >.

Definition at line 63 of file halfspaceD2.h.

Referenced by d3tess::initialize(), d3tess::isconvex(), d3tess::move_terminated(), d2simplexSeparateAxis::sees(), d3tess::surfaceviewable(), and halfspaceD2test::test01().

00064     { return 0 < (x.x-p0.x)*normal.x + (x.y-p0.y)*normal.y; }

template<typename PT, typename PD>
boolc halfspaceD2< PT, PD >::isInsideOrOnBoundary ( PT const &  x  )  const [inline]

Is the point on or inside the half space?

Definition at line 67 of file halfspaceD2.h.

Referenced by halfspaceD2test::test01().

00068     { return 0 < zero<PD>::val+(x.x-p0.x)*normal.x + (x.y-p0.y)*normal.y; }

template<typename PT, typename PD>
boolc halfspaceD2< PT, PD >::isOnBoundary ( PT const &  w  )  const [inline, virtual]

The client configures zero for the isOnBoundary routine.

Reimplemented from partitionspace< PT >.

Definition at line 99 of file halfspaceD2.h.

00100   { 
00101     PD x = (p1.y-p0.y)*(w.x-p0.x) - (p1.x-p0.x)*(w.y-p0.y);
00102     if ( 0 < (x + zero<PD>::val) )
00103     {
00104       if (x < zero<PD>::val)
00105         return true;
00106     }
00107 
00108     return false;  
00109   }

template<typename PT, typename PD>
void halfspaceD2< PT, PD >::minimizepointtoline ( PD &  t,
PT const &  w 
) const [inline]

Find the nearest point on the line to w.

Definition at line 120 of file halfspaceD2.h.

Referenced by halfspaceD2< PT, PD >::distancefromhalfspace(), and halfspaceD2test::test02().

00121   {
00122     PT z(p1-p0);
00123     t=((w.x-p0.x)*z.x+(w.y-p0.y)*z.y)/(z.x*z.x+z.y*z.y);
00124   }

template<typename PT, typename PD>
void halfspaceD2< PT, PD >::normalcalculate (  )  [inline]

Calculate the normal the ordered points.

Definition at line 55 of file halfspaceD2.h.

Referenced by halfspaceD2draw::rotate(), halfspaceD2< PT, PD >::set(), and halfspaceD2draw::translate().

00056   {    
00057     PT t(p1-p0);
00058     normal.x = -t.y;
00059     normal.y = t.x;
00060   }

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

Serialize this object by writing it out as a string.

Definition at line 131 of file halfspaceD2.h.

00132     { stringstream ss; ss << p0 << " " << p1; return ss.str(); }

template<typename PT, typename PD>
template<typename U >
void halfspaceD2< PT, PD >::pointOnLine ( PT &  x,
U const   t 
) const [inline]

Line [p0,p1] for t=[0,1].

Definition at line 74 of file halfspaceD2.h.

Referenced by halfspaceD2< PT, PD >::distancefromhalfspace(), and halfspaceD2test::test02().

00078     { x = p0 + (p1-p0)*t; }

template<typename PT, typename PD>
stringc halfspaceD2< PT, PD >::print (  )  const [inline]

For debug print this object.

Definition at line 135 of file halfspaceD2.h.

00136   { 
00137     stringstream ss; 
00138     ss << SHOW(p0) << " " << SHOW(p1) << " " << SHOW(normal); 
00139     return ss.str();
00140   }

template<typename PT, typename PD >
void halfspaceD2< PT, PD >::set ( PT const &  p0_,
PT const &  p1_ 
) [inline]

Construct a half space from the ordered points.

Left of the directed line.

Definition at line 161 of file halfspaceD2.h.

References halfspaceD2< PT, PD >::normalcalculate(), halfspaceD2< PT, PD >::p0, and halfspaceD2< PT, PD >::p1.

Referenced by partitionstest::test03(), partitionstest::test04(), partitionstest::test05(), and trianglespace< T, D >::trianglespace().

00162 {
00163   p0 = p0_;
00164   p1 = p1_;
00165   normalcalculate();
00166 }


Member Data Documentation

template<typename PT, typename PD>
PT halfspaceD2< PT, PD >::normal

template<typename PT, typename PD>
PT halfspaceD2< PT, PD >::p0

template<typename PT, typename PD>
PT halfspaceD2< PT, PD >::p1


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

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