**1**

# Uniform distribution of points in a 2D convex hull

###
#1
Members - Reputation: **109**

Posted 24 September 2012 - 12:36 PM

Given a set of points N and a convex hull H, how can I place the points in N such that they are uniformly distributed in H? All points in N must be inside of H.

I'm defining uniform distribution in this case to be:

For each point p in N:

the minimum distance between p and (any other point in N OR the perimeter of H) = p_d

All p_d values should have minimal variance for N to be uniformly distributed in H.

I'm looking for a good balance between distribution and time complexity, so approximations are welcome! I'm only concerned about 2D for right now, but solutions that naturally extend to 3D would be awesome.

Thank you,

###
#2
Crossbones+ - Reputation: **14880**

Posted 24 September 2012 - 12:50 PM

###
#3
Crossbones+ - Reputation: **9994**

Posted 26 September 2012 - 07:14 AM

Otherwise, if Poisson disc does not apply in your case for some reason or you are just looking for a more ghetto (or intuitive, depending on your perspective) solution, read on:

If you do not need perfect correctness (i.e. some points may be closer together and others may be further away, or in other words, the variance of the distance should be nonzero but not too large), then another probabilistic way to do it is to generate a regular point lattice with distance equal to your mean minimum distance, and displace each point in every dimension using a Gaussian distribution with your required variance? Like this:

Let be the mean distance between each point, and be the required variance.

1. Generate a regular lattice spaced by in every dimension.

2. For each point in the lattice:

- choose a random angle (or two, if you are in three dimensions) to displace the point in some direction in space

- generate a random variable following a Gaussian distribution* with your variance but with mean 0

- displace the point by units in the direction determined by the angle chosen above

- if the point falls outside or too close to your convex hull, try again until it works (this is biased, but I think it's acceptable given that considering the shape of the hull would likely be intractable)

* see Box-Muller transform to get that from uniform variables

Some examples rendered with a throwaway program, with a mean and a progressively higher variance (from 0 to 0.0003) - remember to square root the variance if you need the standard deviation:

Obviously, as variance increases, the distribution tends to perfect uniformity (assuming an infinite lattice - if it is finite, the algorithm will degenerate).

The 3D situation is exactly the same, your lattice is now 3D and you are displacing the points according to two angles (spherical coordinates i.e. azimuth and elevation instead of just rotation in 2D), but you still only need one Gaussian distribution sample.

**Edited by Bacterius, 26 September 2012 - 07:31 AM.**

The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

- *Pessimal Algorithms and Simplexity Analysis*

###
#4
Crossbones+ - Reputation: **2971**

Posted 27 September 2012 - 01:37 AM

**Poisson disk sampling,**not a

**uniform distribution**of points. In a uniform distribution, every point inside your polygon would be equally probable, with no consideration for their distances; your "uniform" property is actually called

**low discrepancy**,

If you care a lot about equalizing distances between samples, you should start from the right number of uniformly distributed samples, build their Voronoi graph, and move them iteratively until each of them has satisfying distances from its closest neighbours (and maybe from the polygon edges or from samples outside the polygon). For example, you could pretend that the samples are material points and move them with forces computed from Delaunay edges: if they are shorter than the median they push and if they are longer than the median they pull.