Fastest way to Shoelace formula
<p>I have made a function who calculate area polygon with Shoelace way.</p>

<p>That's works perfectly but right now I wonder if there is not a faster way to have the same result.
I want to know that because this function must work faster with polygon with a lot of coordinates.</p>

<p>My function : </p>

<pre><code>def shoelace_formula(polygonBoundary, absoluteValue = True):
    nbCoordinates = len(polygonBoundary)
    nbSegment = nbCoordinates - 1

    l = [(polygonBoundary[i+1][0] - polygonBoundary[i][0]) * (polygonBoundary[i+1][1] + polygonBoundary[i][1]) for i in xrange(nbSegment)]

    if absoluteValue:
        return abs(sum(l) / 2.)
    else:
        return sum(l) / 2.
</code></pre>

<p>My polygon : </p>

<pre><code>polygonBoundary = ((5, 0), (6, 4), (4, 5), (1, 5), (1, 0))
</code></pre>

<p>Result : </p>

<pre><code>22.
</code></pre>

<p>Any ideas? </p>

<p>I try with Numpy : 
It's speedest but you have to convert your coordinates first.</p>

<pre><code>import numpy as np
x, y = zip(*polygonBoundary)

def shoelace_formula_3(x, y, absoluteValue = True):

    result = 0.5 * np.array(np.dot(x, np.roll(y, 1)) - np.dot(y, np.roll(x, 1)))
    if absoluteValue:
        return abs(result)
    else:
        return result
</code></pre>