def area(polygon):
    """
    Calculate the area of a polygon. Can be positive (clockwise) or negative
    (anticlockwise)

    Input

    polygon   [ (r1, z1), (r2, z2), ... ]
    """
    nvert = len(polygon)
    area = 0.0
    for i in range(nvert):
        r1, z1 = polygon[i]
        r2, z2 = polygon[(i + 1) % nvert]
        area += (r2 - r1) * (z1 + z2)
    return 0.5 * area
