Computational Geometry: Regular Distribution of Points inside of a Polygon


So I am basically asking since I struggle to figure out if there is an efficient way to do this. Basically I want to be able to take any arbitrary polygon and fill it with particles as shown in this figure:

The link includes some code based on a Python package to achieve this - I wondered if someone might have made a package like this for Julia?

Kind regards

1 Like

See also this discussion: Mesh/grid over convex polytope (and also Is there a simple way to generate uniform points within a given region?). The former thread includes example code that produces a picture very similar to the one you linked.

1 Like

This is an upcoming feature of GeoStats.jl, particularly the PointPatterns.jl submodule. The problem of sampling points with certain characteristics inside a geometry is known in the literature as point pattern analysis and synthesis. Currently, we have some methods to sample inside hyperrectangles ( but to generalize these methods to arbitrary polygons we need to first address a major milestone in the project regarding general finite element meshes. It is the next item in my TODO list. Meanwhile, I think you could achieve a similar result by generating random numbers in the bounding box of the polygon, and then taking an intersection. @visr and @evetion may have thoughts on this as well.

Oh wauw thanks to both of you.

@stevengj I will be looking at that example now thanks.

@juliohm seems interesting and thank you very much for the correct terminology! Makes future searches much easier.

Kind regards

Okay, so now I have gotten it to work on my polygon:

And now my next step would be to make something like the grey particles in this picture below:


Would anyone happen to know if there is an easy way using LazySets to do this?

Kind regards

1 Like

There is no internal representation for the red curve (“solid boundary profile”) in LazySets. Not sure that i understood what you are trying to achieve, but to draw implicit plots like these you can use ImplicitPlots.jl. If you know how to test if the point is inside/outside the given region, then you can use the same idea of rejection sampling from the other discussion and make such plot.

For future reference, this is what is currently possible:

using GeoStats
using Plots

# rectangular region of interest
r = RectangleRegion((0.,0.), (100.,100.))

# Poisson process with λ=0.1 intensity
p = PoissonProcess(0.1)

# two samples from the process
s = rand(p, r, 2)

plot(plot(s[1]), plot(s[2]))

# superposition of two Binomial processes
p₁ = BinomialProcess(20)
p₂ = BinomialProcess(80)
p  = p₁ ∪ p₂ # 100 points

s = rand(p, r, 2)

plot(plot(s[1]), plot(s[2]))

Notice that this method works in N-dimensional regions. The plan is to handle other types of regions (e.g. polygons, polyhedrons) in the next minor release.

Hi again!

I am playing a bit around with the PoissonProcess. When I have generated “s”, how do I go about extracting the number of elements?

I think it is in the type, so that is why length/size does not work, could you explain it to me?

EDIT: Figured it out, one uses s[1].coords then size works as usual, my bad

Kind regards