Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Area of a Convex Polygon by martin_b
# the area under any two points from the x axe is the rectangle with the
# height y of the lower of the two points plus triangle with the height of
# the difference between the heights of the points; times the difference in x
# the area of the rectangle is composed of areas of the upper parts minus
# areas of the lower parts; what is lower and upper is determined by the
# sign of the difference in x coordinates of the points
# the upper and lower parts may be switched, take the absolute value
def checkio(data):
area = 0
for i, (ax, ay) in enumerate(data):
bx, by = data[i - 1]
area += (min(ay, by) + abs(by - ay) / 2) * (bx - ax)
return abs(area)
Nov. 9, 2017