Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Concave Too solution in Uncategorized category for Area of a Convex Polygon by PositronicLlama
"""
Compute the area of a polygon.
"""
def checkio(data):
"""Return the area of a polygon, given as a list of [x, y] coordinates."""
return abs(sum((x1+x2) * (y2-y1) / 2 for [x1, y1], [x2, y2] in zip(data, data[1:] + data[:1])))
if __name__ == '__main__':
assert checkio([[1, 1], [9, 9], [9, 1]]) == 32, "The half of the square"
assert checkio([[4, 10], [7, 1], [1, 4]]) == 22.5, "Triangle"
assert checkio([[1, 2], [3, 8], [9, 8], [7, 1]]) == 40, "Quadrilateral"
assert checkio([[3, 3], [2, 7], [5, 9], [8, 7], [7, 3]]) == 26, "Pentagon"
assert checkio([[7, 2], [3, 2], [1, 5],
[3, 9], [7, 9], [9, 6]]) == 42, "Hexagon"
assert checkio([[4, 1], [3, 4], [3, 7], [4, 8],
[7, 9], [9, 6], [7, 1]]) == 35.5, "Heptagon"
Aug. 25, 2013
Comments: