def signed_area ( coords ) : xs , ys = map ( list , zip ( * coords ) ) xs . append ( xs [ 1 ] ) ys . append ( ys [ 1 ] ) return sum ( xs [ i ] * ( ys [ i + 1 ] - ys [ i - 1 ] ) for i in range ( 1 , len ( coords ) ) ) / 2.0
calculate the area under a curve python
Return the signed area enclosed by a ring using the linear time algorithm . A value > = 0 indicates a counter - clockwise oriented ring .
def signed_area(coords):
    """Return the signed area enclosed by a ring using the linear time
    algorithm. A value >= 0 indicates a counter-clockwise oriented ring.
    """
    xs, ys = map(list, zip(*coords))
    xs.append(xs[1])
    ys.append(ys[1])
    return sum(xs[i]*(ys[i+1]-ys[i-1]) for i in range(1, len(coords)))/2.0