How to calculate the area of a polygon? [duplicate]

Solution 1:

Let us assume that polygon P has vertices (x1,y1), ..., (xn,yn). Then we can represent the area of the polygon as a sum of trapezoids T(1,2)=(x1,y1)-(x1,0)-(x2,0)-(x2,y2), ..., T(n,1), where area can be counted with opposite sign if x2 < x1:

area(P) = area(T(1,2)) + area(T(2,3)) + ... + area(T(n,1))

and obviously

area(T(i,j)) = (xj-xi)*(yj+yi)/2