Random distribution within part of a circle within a grid cell

Viewed 24

Lets say I have a grid for spatial hashing. I am looking for a way to generate a set of randomly distributed points for each hash cell so the points are created within the portion of the circle that 'falls' in the cell. For example, in the image below, if I were to iterate through each hash cell, how would I generate points ONLY within the shaded portion of the circle for each cell?

enter image description here

I realize that the more simple solution would to be to generate the points within the circle's radius, then stick em all in the spatial hash grid. However, the points I am generating are for graph nodes to be connected through randomly created edges. I could start creating edges as nodes are inserted in their appropriate hash cell but because they are being created randomly, so are their edges and it creates unwanted crisscrossing intersections.

Therefore, I am thinking I could iterate through each hash cell, generate a set amount of points/nodes then connect them all before moving to the next cell. This way -- at least in my mind -- this would reduce the amount of intersecting edges as I could enforce a maximum distance for each one, but also ensure that all nodes within the cell are connected.

This would be easy enough if I was not concerned with the 'shape' of the distribution but I do want these nodes to stay inside the radius of a circle. So is there a way of generating points ONLY within the shaded portion of the circle by iterating through each cell?

1 Answers

You could subdivide each of the cells that overlap the edges of the circle into smaller cells. For example, into a 2 by 2 grid per cell, 3 by 3 grid etc.

Then you could generate points only within the smaller grid cells that are completely covered by the circle. There would be some spots on the circle that would never have points generated in them, but all of the ones that are generated would be within the circle. You can, of course, use smaller and smaller grid cells to get a better and better approximation if you need to.

Related