Message |
If you are just trying to calculate the area of a polygon from a list of x,y coordinates, the general method is to loop through the coordinates performing a cross-product calculation between consecutive coordinate pairs, while summing up a running total. The running total is then divided by 2 and the absolute value is taken to yield the final result or area of the polygon.
Care must be taken to close the polygon by traversing the coordinates back to the origin point. For example, if I have a 5-sided polygon defined by the array
0,1
3,3
5,3
6,2
5,0
the last calculation would involve the 5,0 point and the 0,1 origin point.
If n is the number of coordinates in the polygon, and assuming a zero-based array, where the first coordinates are at array index 0 and the last coordinates are at index n-1, computer code would look something like the following, depending on the language used and your array: |