Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Area of a Convex Polygon by Moff
from collections import namedtuple
from math import sqrt
Point = namedtuple('Point', 'x y')
def triangle_area(p1, p2, p3):
a = (p1.x - p2.x) ** 2 + (p1.y - p2.y) ** 2
b = (p1.x - p3.x) ** 2 + (p1.y - p3.y) ** 2
c = (p2.x - p3.x) ** 2 + (p2.y - p3.y) ** 2
return sqrt((a + b + c) ** 2 - 2 * (a ** 2 + b ** 2 + c ** 2)) / 4
def checkio(src):
points = [Point(*row) for row in src]
result = 0
for i in range(2, len(points)):
result += triangle_area(points[0], points[i], points[i-1])
return result
Aug. 13, 2015