Mirror

How to calculate the area of a polygon (Views: 100)


Problem/Question/Abstract:

How to calculate the area of a polygon

Answer:

The signed area can be computed in linear time by a simple sum. The key formula is this: If the coordinates of vertex v_i are x_i and y_i, twice the signed area of a polygon is given by:



2 A( P ) = sum_{i = 0}^{n - 1} (x_i y_{i + 1} - y_i x_{i + 1})



Here n is the number of vertices of the polygon. A rearrangement of terms in this equation can save multiplications and operate on coordinate differences, and so may be both faster and more accurate:



2 A( P ) = sum_{i = 0}^{n - 1} ((x_i + x_{i + 1}) (y_{i + 1} - y_i))


To find the area of a planar polygon not in the x-y plane, use:


2 A(P) = abs(N . (sum_{i = 0}^{n - 1} (v_i x v_{i + 1})))



where N is a unit vector normal to the plane. The '.' represents the dot product operator, the 'x' represents the cross product operator, and abs() is the absolute value function.

<< Back to main page