proj home

Files   Classes   Functions   Hierarchy  

d3mincentroid.cpp

Go to the documentation of this file.
00001 
00002 #include <d3tess.h>
00003 #include <d3mincentroid.h>
00004 
00005 
00006 
00007 typedef point2<double> pt2;
00008 typedef point3<double> pt3;
00009 
00010 #define SHOW(x) #x << '=' << (x)
00011 
00012 
00013 
00014 d3mincentroid::d3mincentroid(d3tess & tess_)
00015   : d3minoperator(tess_)
00016 {
00017 }
00018 
00019 boolc d3mincentroid::eval(uintc a, uintc b)
00020 {
00021   if (tess.isconvex(a,b)==false)
00022     return false;
00023 
00024   simplexD2linked const & A(tess.vi[a]);
00025   simplexD2linked const & B(tess.vi[b]);
00026 
00027   uint ai = A.niInverse(b);
00028   uint bi = B.niInverse(a);
00029 
00030   uint p[4];
00031   p[0] = A.pi[ai];
00032   p[3] = B.pi[bi];
00033   p[1] = A.pi[(ai+1)%3];
00034   p[2] = A.pi[(ai+2)%3];
00035 
00036   vector<pt3> const & pt(tess.pt);
00037 
00038   pt2 P0(pt[p[0]]);
00039   pt2 P1(pt[p[1]]);
00040   pt2 P2(pt[p[2]]);
00041   pt2 P3(pt[p[3]]);
00042 
00043   // Calculate the centroid.
00044   pt2 C0(P0);
00045   C0 += P1;
00046   C0 += P2;
00047   C0 *= (1.0/3.0);
00048 
00049   // Calculate the average radius of points to the centroid.
00050   double radius(0.0);
00051   radius += (C0-P0).distance();
00052   radius += (C0-P1).distance();
00053   radius += (C0-P2).distance();
00054   radius /= 3.0;
00055 
00056   if ((C0-P3).dot() > radius*radius )
00057     return false;
00058 
00059   tess.flip(a,b);
00060 
00061   return true;
00062 }
00063 
00064 

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