**polygon_grid**,
a Python code which
generates a grid of points
over the interior of a polygon in 2D.

The program relies on a simple idea in which the "vertex centroid" (average of the vertices) is computed, allowing the polygon to be triangulated. Each triangle can then easily be gridded. The collection of triangular grids joins up to form a grid over the polygon, although the spacing of the the grid points will vary from triangle to triangle.

The program really only works properly for convex polygons. If the polygon is not convex, then the vertex centroid need not lie inside the polygon, consequently the grid points may also seem misaligned.

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

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

ball_grid, a python code which computes a grid of points over the interior of a ball in 3d.

circle_arc_grid, a python code which computes points equally spaced along a circular arc;

cube_grid, a python code which computes a grid of points over the interior of a cube in 3d.

disk_grid, a python code which computes a grid of points over the interior of a disk in 2d.

ellipse_grid, a python code which computes a grid of points over the interior of an ellipse in 2d.

ellipsoid_grid, a python code which computes a grid of points over the interior of an ellipsoid in 3d.

hypercube_grid, a python code which computes a grid of points over the interior of a hypercube in m dimensions.

line_grid, a python code which computes a grid of points over the interior of a line segment in 1d.

polygon_integrals, a python code which returns the exact value of the integral of any monomial over the interior of a polygon in 2d.

polygon_monte_carlo, a python 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 python 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 python code which triangulates a possibly nonconvex polygon.

pyramid_grid, a python code which computes a grid of points over the interior of the unit pyramid in 3d;

simplex_grid, a python code which generates a grid of points over the interior of a simplex in m dimensions.

sphere_fibonacci_grid, a python code which uses a fibonacci spiral to create a grid of points on the surface of the unit sphere in 3d.

sphere_llq_grid, a python code which uses longitudes and latitudes to create grids of points, lines, and quadrilaterals on the surface of the unit sphere in 3d.

sphere_llt_grid, a python code which uses longitudes and latitudes to create grids of points, lines, and triangles on the surface of the unit sphere in 3d.

square_grid, a python code which computes a grid of points over the interior of a square in 2d.

tetrahedron_grid, a python code which computes a grid of points over the interior of a tetrahedron in 3d.

triangle_grid, a python code which computes a grid of points over the interior of a triangle in 2d.

wedge_grid, a python code which computes a grid of points over the interior of the unit wedge in 3d.

- polygon_grid.py, the source code.
- polygon_grid.sh, runs all the tests.
- polygon_grid.txt, the output file.

ELL is an L-shaped (non-convex!) polygon for which the program output doesn't look too bad, although the grid is degenerate.

QUAD is a quadrilateral polygon.

TRIANGLE is a triangular polygon.

- triangle.png a plot of the grid.
- triangle.xy the grid points.