HiveBrain v1.2.0
Get Started
← Back to all entries
patternModerate

Random sampling in a polygon

Submitted by: @import:stackexchange-cs··
0
Viewed 0 times
randomsamplingpolygon

Problem

I would like to sample a uniformly random point in a polygon...

If sample a large number they'd be equally likely to fall into two regions if they have the same area.

This would be quite simple if it were a square since I would take two random numbers in [0,1] as my coordinates.

The shape I have is a regular polygon, but I'd like it to work for any polygon.

https://stackoverflow.com/questions/3058150/how-to-find-a-random-point-in-a-quadrangle

Solution


  • Triangulate the polygon



  • Determine in which of the triangles the point should lie (weights triangle areas)



  • Sample the point in the triangle as explained in this post

Context

StackExchange Computer Science Q#14007, answer score: 10

Revisions (0)

No revisions yet.