Polygon Area and Centroidsys502/extra_materials/Polygon Area and... · Note for polygons with...

download Polygon Area and Centroidsys502/extra_materials/Polygon Area and... · Note for polygons with holes. The holes are usually defined by ordering the vertices of the enclosing polygon

If you can't read please download the document

Transcript of Polygon Area and Centroidsys502/extra_materials/Polygon Area and... · Note for polygons with...

  • C a l c u l a t i n g T h eA r e a A n d

    C e n t r o i d O f AP o l y g o n

    Written by Paul BourkeJuly 1988

    Sample source codeThis C function returns the area of apolygon.JAVA code submitted by RamnTalavera.PolygonUtilities.java contributed byChristopher FuhrmanPascal/Dephi example by RodrigoAlves Pons.Basic version also by Rodrigo AlvesPons.

    Area

    The problem of determining the area of a polygon seems at best messy but the finalformula is particularly simple. The result and sample source code (C) will bepresented here. Consider a polygon made up of line segments between N vertices(xi,yi), i=0 to N-1. The last vertex (xN,yN) is assumed to be the same as the first, ie:the polygon is closed.

    The area is given by

    Polygon Area and Centroid http://local.wasp.uwa.edu.au/~pbourke/geometry/polyarea/

    1 of 3 4/1/2009 12:42 PM

  • Note for polygons with holes. The holes are usually defined by ordering the verticesof the enclosing polygon in the opposite direction to those of the holes. Thisalgorithm still works except that the absolute value should be taken after adding thepolygon area to the area of all the holes. That is, the holes areas will be of oppositesign to the bounding polygon area.

    The sign of the area expression above (without the absolute value) can be used todetermine the ordering of the vertices of the polygon. If the sign is positive then thepolygon vertices are ordered counter clockwise about the normal, otherwiseclockwise.

    To derive this solution, project lines from each vertex to some horizontal line belowthe lowest part of the polygon. The enclosed region from each line segment is madeup of a triangle and rectangle. Sum these areas together noting that the areas outsidethe polygon eventually cancel as the polygon loops around to the beginning.

    The only restriction that will be placed on the polygon for this technique to work isthat the polygon must not be self intersecting, for example the solution will fail inthe following cases.

    Centroid

    The centroid is also known as the "centre of gravity" or the "center of mass". Theposition of the centroid assuming the polygon to be made of a material of uniformdensity is given below. As in the calculation of the area above, xN is assumed to be

    Polygon Area and Centroid http://local.wasp.uwa.edu.au/~pbourke/geometry/polyarea/

    2 of 3 4/1/2009 12:42 PM

  • x0, in other words the polygon is closed.

    Centroid of a 3D shell described by 3 vertex facets

    The centroid C of a 3D object made up of a collection of N triangular faces withvertices (ai,bi,ci) is given below. Ri is the average of the vertices of the i'th face and Aiis twice the area of the i'th face. Note the faces are assumed to be thin sheets ofuniform mass, they need not be connected or form a solid object. This reduces to theequations above for a 2D 3 vertex polygon.

    Polygon Area and Centroid http://local.wasp.uwa.edu.au/~pbourke/geometry/polyarea/

    3 of 3 4/1/2009 12:42 PM