proj home

Files   Classes   Functions   Hierarchy  

arcsconnected.cpp

Go to the documentation of this file.
00001 #include <fstream>
00002 using namespace std;
00003 
00004 #include <arcsconnected.h>
00005 
00006 
00007 // TOTALLY UNTESTED <TODO>
00008 void arcsconnected::constructPhi0
00009 ( 
00010   doublec phi0, 
00011   vector< pt2 > const & pts 
00012 )
00013 {
00014   assert(pts.size()==N+1);
00015   assert(pts.size()>=2);
00016   if (pts.size()<2)
00017     return;
00018 
00019   arc a;
00020   a.constructPhi0TwoPoints(phi0,pts[0],pts[1]);
00021   double r0 = a.radius;
00022 
00023   constructR0(r0,pts);
00024 }
00025 
00026 void arcsconnected::constructR0
00027 (
00028   doublec r0, 
00029   doublec * pts
00030 )
00031 {
00032   pt2 * v = & constructR0Vec[0];
00033   pt2 * const vend = v + N + 1;
00034   doublec *p = pts;
00035   for ( ; v!=vend; )
00036   {
00037     (*v).x = *p;
00038     ++p;
00039     (*v).y = *p;
00040     ++p;
00041     ++v;
00042   }
00043 
00044   constructR0(r0,constructR0Vec);
00045 
00046   //assert(false) // UNTESTED ROUTINE<TODO>
00047 }
00048 
00049 void arcsconnected::constructR0
00050 ( 
00051   doublec r0, 
00052   vector< pt2 > const & pts 
00053 )
00054 {
00055   assert(pts.size()==N+1);
00056   assert(pts.size()>=2);
00057   if (pts.size()<2)
00058     return;
00059 
00060   vi[0].constructRadiusTwoPoints(r0,pts[0],pts[1]);
00061 
00062   double theta;
00063   for (uint i=1; i<N; ++i)
00064   {
00065     pt2c & p0(pts[i]);
00066     pt2c & p1(pts[i+1]);
00067     pt2c & c0(vi[i-1].center);
00068 
00069     theta = vi[i-1].phi1;
00070 
00071 //cout << SHOW(theta*radtodeg) << endl;
00072 
00073     // Is the new point above the tangent?
00074     // This is a halfspace test.
00075     if ( (p0-c0).dot(p1-p0) > 0.0 )
00076     {
00077       theta += PI;
00078       if (theta >= PI*2.0)
00079         theta -= PI*2.0;
00080     }
00081 
00082 //cout << SHOW(theta*radtodeg) << endl;
00083       
00084     vi[i].constructPhi0TwoPoints(theta,pts[i],pts[i+1]);
00085   }
00086 }
00087 
00088 
00089 arcsconnected::arcsconnected(uintc nstates, uintc _N)
00090   : N(_N), cb(nstates,_N)
00091 {
00092   vi.resize(N);
00093   constructR0Vec.resize(N+1);
00094 }
00095 
00096 
00097 void arcsconnected::arcwriter( stringc filename ) const
00098 {
00099   ofstream targ(filename.c_str(),ios::trunc);
00100 
00101   assert(targ.good()==true);
00102   if (targ.good()==false)
00103     return;
00104 
00105   targ << N+1 << endl;
00106   for (uint i=0; i<N; ++i)
00107     targ << vi[i].p0 << endl;
00108   targ << vi[N-1].p1 << endl;
00109 
00110   targ << N << endl;
00111   for (uint i=0; i<N ; ++i)
00112     targ << i << " " << i+1 << " " << vi[i].radius << endl;
00113 
00114 }
00115 
00116 void arcsconnected::sumdisttoarc
00117 ( 
00118   double & sum,
00119   vector< pt2 > const & qi 
00120 ) const 
00121 {
00122   uintc W = qi.size();
00123 
00124   sum=0.0;
00125   double val;
00126   double val2;
00127   for (uint i=0; i<N; ++i)
00128   {
00129     arc const & a(vi[i]);
00130     a.distanceSquared(val,qi[0]);
00131 
00132     for (uint k=0; k<W; ++k)
00133     {
00134       a.distanceSquared(val2,qi[k]);
00135       if (val2<val)
00136         val=val2;
00137     }
00138 
00139     sum += val;
00140   }
00141 }
00142 
00143 
00144 

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