-1

I would like to know how to create some circles without overlapping in Python.

Let me share a part of my script A screenshot, describing the source code.

In lines 55,56 and 57 I print the coordinates, witnessing overlapping. Inside each for statement I thought I avoided the overlapping doing something like bisection method (root finding method).

The source code works good for 5 or 6 voids but when increasing the number of voids I get overlapping.

ShadowRanger
  • 143,180
  • 12
  • 188
  • 271
Andres Valdez
  • 164
  • 17
  • I would said from the top of my head: have a list of circles already make, and a function to check for overlapping of 2 circles, then in a loop create a new random circle and check for overlaping with all the previous one, is no overlap is found, add it to the list, otherwise reject it. Repeat until the desire number of circles are reached or you fail too much as to conclude that is no possible anymore – Copperfield Jan 07 '18 at 23:37
  • 3
    Hi and Welcome to StackOverflow, please don't put images of code, instead put code directly into your question as formatted text (using the `{}` markdown button in the question form), thanks – chickity china chinese chicken Jan 07 '18 at 23:38
  • 2
    Possibly related or helpful [Python Pygame randomly draw non overlapping circles](https://stackoverflow.com/questions/46702987/python-pygame-randomly-draw-non-overlapping-circles) – chickity china chinese chicken Jan 07 '18 at 23:42
  • @Copperfield Oks thanks for the advice, will try to use some kind of list with saved coordinates and radius to avoid the overlapping. – Andres Valdez Jan 07 '18 at 23:52
  • @davedwards I tried to use the previous answer, from your suggestion. Seems that I will need to store coordinates and radius and evaluate new circles against the already stored... – Andres Valdez Jan 07 '18 at 23:54
  • from the top of my head. create a voronoi diagram from random points and make the circles radius smaller then the one touching it? – Nokdu Jan 08 '18 at 00:12

1 Answers1

2

Your maximum radius is B=10. So assuming you want points separated by maximum radius, you could sample such points using Poisson disk algorithm.

Then, having sampled centers, draw random radius around each center, and they wont overlap because all radii are smaller than your max.

Severin Pappadeux
  • 18,636
  • 3
  • 38
  • 64