Shoelace formula for polygonal area

From Rosetta Code
Shoelace formula for polygonal area is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

Write a function/method/routine to use the the Shoelace formula to calculate the area of the polygon described by the ordered points:

    (3,4), (5,11), (12,8), (9,5), and (5,6)

Show the answer here, on this page.


Template:Python

<lang python>>>> def area_by_shoelace(x, y):

   "Assumes x,y points go around the polygon in one direction"
   return abs( sum(i * j for i, j in zip(x,             y[1:] + y[:1]))
              -sum(i * j for i, j in zip(x[1:] + x[:1], y            ))) / 2

>>> points = [(3,4), (5,11), (12,8), (9,5), (5,6)] >>> x, y = zip(*points) >>> area_by_shoelace(x, y) 30.0 >>> </lang>