Jump to content

View more

Image of the Day

#ld38 #screenshotsaturday Mimosa Fizz action gif #2 https://t.co/TUzdppvfUL
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Sign up now

Uniform distribution of points in a 2D convex hull

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Bioq   Members   


Posted 24 September 2012 - 12:36 PM

Hi all,

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 Álvaro   Members   


Posted 24 September 2012 - 12:50 PM

This is a tricky problem. The first thing I would try is to throw the points in following a uniform random distribution and then iterate through the process of finding the closest pair of points and pushing both of them away from each other a little bit. See if you can get reasonable results with that.

#3 Bacterius   Members   


Posted 26 September 2012 - 07:14 AM

A Poisson disc would be perfect for your needs, as it specifically focuses on keeping a minimal distance between sample points. You'll still need to check intersection with the hull in case a point happens to fall outside it by chance.

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:

Posted Image

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.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

#4 LorenzoGatti   Members   


Posted 27 September 2012 - 01:37 AM

I need to insist on proper language: you want 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.

Omae Wa Mou Shindeiru

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.