Geometry – How to Distribute Points Uniformly Inside a Polygon

geometry

I have a polygon in 2D (defined by a series of Vertex $V$ with coordinates). The polygon can be convex or concave. I have $n$ number of fix points I can put inside the polygon.

The question is, how can I distribute the fix points as uniformly as possible inside the polygon?

The motivation for this question is I want to create a mesh generator and I want all the triangular elements $E$ ( which is defined by a list of vertices $V$) to look good with no too small or too large angles. In order to control the granularity of the mesh I am thinking about using the number of fix points $n$ as the controlling parameter. The fix points are used to control the vertex of the triangular elements.

Is there any algorithm for this?

Best Answer

Just dropping points into the polygon according to a uniform distribution will not, unfortunately, generate very uniform solutions: with extremely high probability there will be large gaps and tight clusters.

Obtaining a highly uniform pattern within an arbitrary (convex) polygon is a difficult problem to solve; exact solutions are known only for special polygons and very small numbers of points. As the number of points $n$ grows, they tend to fall into a hexagonal pattern. However, like real crystals, these patterns can exhibit faults and fractures imposed by the polygon's boundary. As a quick and dirty solution you might estimate the average spacing by dividing the polygon's area by $n$ and solving for the dimensions of a hexagon of that area, creating an hexagonal mesh of those dimensions, and performing some trial overlays of that mesh (translating it a bit in each trial) to find something that works well. You are likely to run into trouble at places just inside the polygon's boundary, though.

One practical way to find solutions that really work is with spatial simulated annealing. Although that's a computationally intensive and purely approximate approach, in practice you can get reasonable solutions for the intended application in an extremely short time (thousands of iterations rather than hundreds of thousands).