0

I am making a game which spawns scattered x number of points. All Points have a constant radius of w

The points must follow these rules:

  • Points may not overlap other points
  • Points must be spread apart so that each point is at least DISTANCE away from any other points.

Can you please list an efficient algorithm to execute this?

I am also making this game in Swift Sprite-Kit. So if you know some Sprite-Kit, you can implement it in your answer, otherwise if you do not know Swift or Sprite-Kit you can explain in words.

Entitize
  • 4,553
  • 3
  • 20
  • 28

1 Answers1

1

Your two constraints are equivalent. It means the distance between any two points must be at least max(w, DISTANCE).

The easiest way is to generate random points and check the minimum distance to previous points. If the constraint is not fulfilled, just generate a new point. You can speed up the distance checking with a simple grid (put points in the grid cells and then just check the cells that may contain overlapping points).

Nico Schertler
  • 32,049
  • 4
  • 39
  • 70