Skip to content

polygonArea

David Legland edited this page Feb 28, 2022 · 1 revision

Compute the signed area of a polygon.

Usage

A = polygonArea(POINTS);

Compute area of a polygon defined by POINTS. POINTS is a N-by-2 array of double containing coordinates of vertices.

Vertices of the polygon are supposed to be oriented Counter-Clockwise (CCW). In this case, the signed area is positive. If vertices are oriented Clockwise (CW), the signed area is negative.

If polygon is self-crossing, the result is undefined.

Examples

Computes the area of a simple shape

  poly = [10 10;30 10;30 20;10 20];
  area = polygonArea(poly)

Result:

  area = 
      200

Computes the area of a CW polygon

  area2 = polygonArea(poly(end:-1:1, :))

Result:

  area2 = 
      -200

Computes the area of a "paper hen" shape

  x = [0 10 20  0 -10 -20 -10 -10  0];
  y = [0  0 10 10  20  10  10  0 -10];
  poly = [x' y'];
  area = polygonArea(poly)

Result:

  area =
     400

Area of unit square with 25% hole

  pccw = [0 0; 1 0; 1 1; 0 1];
  pcw = pccw([1 4 3 2], :) * .5 + .25;
  polygonArea ([pccw; nan(1,2); pcw])

Result:

  ans =
     0.75

References

algo adapted from P. Bourke web page [http://paulbourke.net/geometry/polygonmesh/]

See also

polygons2d, polygonCentroid, polygonSecondAreaMoments, triangleArea