The polygons can be regular or irregular. For example,
Regular or Irregular Polygons
The following idea is the easiest way to compute its area (signed) for any given simple 2-D polygons, even for concave ones.
1. Compute the value
2. Sum them up:
The C# code shown following clearly illustrates the idea.
public static double area(double[] x, double[] y, int n)
{
double area = 0.0;
for (int i = 1; i < n; i++)
{
area += (x[i] - x[i - 1]) * (y[i] + y[i - 1]) * 0.5;
}
area += (x[0] - x[n - 1]) * (y[0] + y[n - 1]) * 0.5;
return area;
}
Let’s try to compute the following polygon.
Example Concave Polygon, Algorithm to compute its signed area
We loop each edge and compute the sum of the difference of width multiply the average height.
The compute process is like following.
Table, process to compute the signed area of a polygon
For more information, you might visit this page.
–EOF (The Ultimate Computing & Technology Blog) —
Last Post: Codeforces: 236A. Boy or Girl ?
Next Post: Algorithm Complexity