def getPolygonCenter(polygon):
 pointSum = complex()
 areaSum = 0.0
 for pointIndex in xrange(len(polygon)):
  pointBegin = polygon[pointIndex]
  pointEnd = polygon[((pointIndex + 1) % len(polygon))]
  area = ((pointBegin.real * pointEnd.imag) - (pointBegin.imag * pointEnd.real))
  areaSum += area
  pointSum += (complex((pointBegin.real + pointEnd.real), (pointBegin.imag + pointEnd.imag)) * area)
 return ((pointSum / 3.0) / areaSum)

def getPolygonCenter ( polygon ) : pointSum = complex ( ) areaSum = 0.0 for pointIndex in xrange ( len ( polygon ) ) : pointBegin = polygon [ pointIndex ] pointEnd = polygon [ ( ( pointIndex + 1 ) % len ( polygon ) ) ] area = ( ( pointBegin . real * pointEnd . imag ) - ( pointBegin . imag * pointEnd . real ) ) areaSum += area pointSum += ( complex ( ( pointBegin . real + pointEnd . real ) , ( pointBegin . imag + pointEnd . imag ) ) * area ) return ( ( pointSum / 3.0 ) / areaSum )
get the centroid of a polygon .