area.cpp

00001 
00002 #include "area.h"
00003 
00004 namespace geometry
00005 {
00006 
00007   Point2d centroid( const std::vector<Point2d>& polygon)
00008   {
00009     size_t k = polygon.size();
00010     if(polygon.empty())
00011       return Point2d(0.0);
00012     double a = 0;
00013     Point2d c(0.0);
00014     int j = (int)k-1;
00015     for(size_t i = 0 ; i < k ; ++i)
00016     {
00017       double v = polygon[j] ^ polygon[i];
00018       a += v;
00019       c += v*(polygon[j]+polygon[i]);
00020       j = (int)i;
00021     }
00022     c /= 3*a;
00023     return c;
00024   }
00025 
00026 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Fri May 31 15:37:50 2013 for VVE by  doxygen 1.6.3