def _centroid(vertices):
    """Find the centroid of a polygon."""
    assert vertices[0] == vertices[-1]
    thesum = 0
    vsum = 0, 0
    for i in range(len(vertices) - 1):
        v1 = vertices[i]
        v2 = vertices[i + 1]
        cross = v1[0] * v2[1] - v1[1] * v2[0]
        thesum += cross
        vsum = (v1[0] + v2[0]) * cross + vsum[0], (v1[1] + v2[1]
            ) * cross + vsum[1]
        z = 1.0 / (3.0 * thesum)
    return vsum[0] * z, vsum[1] * z
