polygon_integrals


polygon_integrals, a C++ code which returns the exact value of the integral of any monomial over the interior of a polygon in 2D.

We suppose that POLY is a planar polygon with N vertices X, Y, listed in counterclockwise order.

For nonnegative integers P and Q, the (unnormalized) moment of order (P,Q) for POLY is defined by:

        Nu(P,Q) = Integral ( x, y in POLY ) x^p y^q dx dy
      
In particular, Nu(0,0) is the area of POLY.

Simple formulas are available for low orders:

        Nu(0,0) = 1/2 (1<=i<=N) X(i-1)Y(i)-X(i)Y(i-1)
        Nu(1,0) = 1/6 (1<=i<=N) ( X(i-1)Y(i)-X(i)Y(i-1) ) * (X(i-1)+X(i))
        Nu(0,1) = 1/6 (1<=i<=N) ( X(i-1)Y(i)-X(i)Y(i-1) ) * (Y(i-1)+Y(i))
        Nu(2,0) = 1/12 (1<=i<=N) ( X(i-1)Y(i)-X(i)Y(i-1) ) * (X(i-1)^2+X(i-1)X(i)+X(i)^2)
        Nu(1,1) = 1/24 (1<=i<=N) ( X(i-1)Y(i)-X(i)Y(i-1) ) * (2X(i-1)Y(i-1)+X(i-1)Y(i)+X(i)Y(i-1)+2X(i)Y(i))
        Nu(0,2) = 1/12 (1<=i<=N) ( X(i-1)Y(i)-X(i)Y(i-1) ) * (Y(i-1)^2+Y(i-1)Y(i)+Y(i)^2)
      

The normalized moment of order (P,Q) for POLY is defined by:

        Alpha(P,Q) = Integral ( x, y in POLY ) x^p y^q dx dy / Area ( Poly )
                   = Nu(P,Q) / Nu(0,0)
      
In particular, Alpha(0,0) is 1.

The central moment of order (P,Q) for POLY is defined by:

        x* = Alpha(1,0)
        y* = Alpha(0,1)
        Mu(P,Q) = Integral ( x, y in POLY ) (x-x*)^p (y-y*)^q dx dy / Area ( Poly )
      

Simple formulas are available for low orders:

        Mu(0,0) = 1
        Mu(1,0) = 0
        Mu(0,1) = 0
        Mu(2,0) = Alpha(2,0) - Alpha(1,0)^2
        Mu(1,1) = Alpha(1,1) - Alpha(1,0) * Alpha(0,1)
        Mu(0,2) = Alpha(0,2) - Alpha(0,1)^2
      

Licensing:

The computer code and data files described and made available on this web page are distributed under the MIT license

Languages:

polygon_integrals is available in a C version and a C++ version and a FORTRAN90 version and a MATLAB version and a Python version.

Related Data and Programs:

BALL_INTEGRALS, a C++ code which returns the exact value of the integral of any monomial over the interior of the unit ball in 3D.

CIRCLE_INTEGRALS, a C++ code which returns the exact value of the integral of any monomial over the surface of the unit circle in 2D.

CUBE_INTEGRALS, a C++ code which returns the exact value of the integral of any monomial over the interior of the unit cube in 3D.

DISK01_INTEGRALS, a C++ code which returns the exact value of the integral of any monomial over the interior of the unit disk in 2D.

HYPERBALL_INTEGRALS, a C++ code which returns the exact value of the integral of any monomial over the interior of the unit hyperball in M dimensions.

HYPERCUBE_INTEGRALS, a C++ code which returns the exact value of the integral of any monomial over the interior of the unit hypercube in M dimensions.

HYPERSPHERE_INTEGRALS, a C++ code which returns the exact value of the integral of any monomial over the surface of the unit hypersphere in M dimensions.

LINE_INTEGRALS, a C++ code which returns the exact value of the integral of any monomial over the length of the unit line in 1D.

polygon_integrals_test

POLYGON_MONTE_CARLO, a C++ code which applies a Monte Carlo method to estimate the integral of a function over the interior of a polygon in 2D.

POLYGON_PROPERTIES, a C++ code which computes properties of an arbitrary polygon in the plane, defined by a sequence of vertices, including interior angles, area, centroid, containment of a point, convexity, diameter, distance to a point, inradius, lattice area, nearest point in set, outradius, uniform sampling.

POLYGON_TRIANGULATE, a C++ code which triangulates a possibly nonconvex polygon, and which can use gnuplot to display the external edges and internal diagonals of the triangulation.

PYRAMID_INTEGRALS, a C++ code which returns the exact value of the integral of any monomial over the interior of the unit pyramid in 3D.

SIMPLEX_INTEGRALS, a C++ code which returns the exact value of the integral of any monomial over the interior of the unit simplex in M dimensions.

SPHERE_INTEGRALS, a C++ code which returns the exact value of the integral of any monomial over the surface of the unit sphere in 3D.

SQUARE_INTEGRALS, a C++ code which returns the exact value of the integral of any monomial over the interior of the unit square in 2D.

TETRAHEDRON_INTEGRALS, a C++ code which returns the exact value of the integral of any monomial over the interior of the unit tetrahedron in 3D.

TRIANGLE_INTEGRALS, a C++ code which returns the exact value of the integral of any monomial over the interior of the unit triangle in 2D.

WEDGE_INTEGRALS, a C++ code which returns the exact value of the integral of any monomial over the interior of the unit wedge in 3D.

Reference:

  1. SF Bockman,
    Generalizing the Formula for Areas of Polygons to Moments,
    American Mathematical Society Monthly,
    Volume 96, Number 2, February 1989, pages 131-132.
  2. Carsten Steger,
    On the calculation of arbitrary moments of polygons,
    Technical Report FGBV-96-05,
    Forschungsgruppe Bildverstehen, Informatik IX,
    Technische Universitaet Muenchen, October 1996.

Source Code:


Last revised on 31 March 2020.