Competitive Programing Problem Solutions/Geometry/test (2).cpp
PT ComputeCentroid(const vector<PT>p){
    PT c=PT(0.0,0.0);
    double scale=6.0*ComputeSignedArea(p);
    for(int i=0; i<p.size(); i++){
        int j=(i+1)%p.size();
        c=c+(p[i]+p[j])*(p[i].x*p[j].y-p[j].x*p[i].y);
    }
    return c/scale;
}
/// Computes the centroid of a possibly non-convex polygon, assuming that the coordinates are listed in a clockwise or counterclockwise fashion

Computes the centroid of a possibly non-convex polygon, assuming that the coordinates are listed in a clockwise or counterclockwise fashion
Computes the centroid of a possibly non - convex polygon assuming that the coordinates are listed in a clockwise or counterclockwise fashion
PT ComputeCentroid(const vector<PT>p){
    PT c=PT(0.0,0.0);
    double scale=6.0*ComputeSignedArea(p);
    for(int i=0; i<p.size(); i++){
        int j=(i+1)%p.size();
        c=c+(p[i]+p[j])*(p[i].x*p[j].y-p[j].x*p[i].y);
    }
    return c/scale;
}
PT ComputeCentroid ( const vector < PT > p ) { PT c = PT ( 0.0 , 0.0 ) ; double scale = 6.0 * ComputeSignedArea ( p ) ; for ( int i = 0 ; i < p . size ( ) ; i ++ ) { int j = ( i + 1 ) % p . size ( ) ; c = c + ( p [ i ] + p [ j ] ) * ( p [ i ] . x * p [ j ] . y - p [ j ] . x * p [ i ] . y ) ; } return c / scale ; }
Computes the centroid of a possibly non-convex polygon, assuming that the coordinates are listed in a clockwise or counterclockwise fashion
Computes the centroid of a possibly non - convex polygon assuming that the coordinates are listed in a clockwise or counterclockwise fashion