Editor

Area of a Plot of Land

#296 · Geometry · Intermediate · 70 XP · about 12 min

A surveyor walks once around the border of a plot of land and writes down each corner as an (x, y) tuple of integers, in the order she reaches them. She may walk clockwise or counter-clockwise, and the border never crosses or touches itself.

Write polygon_area(points) that returns the area of the plot as a float.

Examples

polygon_area([(0, 0), (4, 0), (4, 3), (0, 3)])                  # returns 12.0
polygon_area([(0, 0), (3, 0), (0, 5)])                          # returns 7.5
polygon_area([(1, 1), (1, 4), (2, 4), (2, 2), (5, 2), (5, 1)])  # returns 6.0

The last plot is L-shaped and listed clockwise: an upright 1 by 3 strip and a 3 by 1 strip, area 6.

Constraints

  • 3 to 100,000 corners, listed in order around the border; the border closes from the last corner back to the first.
  • Coordinates are between -106 and 106.
  • Three corners in a row may lie on one straight line.

Note

With whole-number corners, every area is a whole number or a whole number and a half, so the float is exact.

Fastest solvers

Leaderboard

First solves only, ranked by stars and then time.