4
$\begingroup$

How can we draw 20 circles which have random radius in a specified range, with random positions. All centers must be in a square with side=10 (for example centimeter):

every overlapping between any circles (their circumference) can happen is it possible to color the circumstances with random colors?!

$\endgroup$
  • 2
    $\begingroup$ This doesn't sound as a question that is particularly aimed at Mathematica; it's more algorithmic of nature and one could develop solutions using brain, pen and paper. Could you indicate what the specific Mathematica angle is here and what you have done so far? $\endgroup$ – Sjoerd C. de Vries Jun 2 '15 at 13:07
  • $\begingroup$ Ok, I am editing that. $\endgroup$ – Unbelievable Jun 2 '15 at 13:21
  • $\begingroup$ at the first I produced a table contained 20 random numbers (as centers) in a range and 20 others (as radius) and plotted (pairs) of them. But I am going to obtain a short way to that. $\endgroup$ – Unbelievable Jun 2 '15 at 13:26
  • 1
    $\begingroup$ I see that you changed your question so it doesn't include non-intersecting circles, but I wanted to point out this tangentially related question nonetheless: Generating visually pleasing circle packs. It would be worth a look for the sheer artistic value alone. $\endgroup$ – MarcoB Jun 2 '15 at 15:44
8
$\begingroup$
centers = RandomReal[{0, 10}, {20, 2}];
radii   = RandomReal[{0, 1}, 20];
Graphics[{MapThread[{RGBColor@@RandomReal[{0, 1}, 3], Circle@##} &, {centers, radii}], 
         FaceForm[Transparent], EdgeForm[Red], 
         Polygon[{{0, 0}, {0, 10}, {10, 10}, {10, 0}, {0, 0}}]}]

Mathematica graphics

Edit

If you want disjoint circles you may go with something like:

SeedRandom[42];
f := {RandomReal[{0, 10}, 2], RandomReal[{0, 1}]}
l = {f};
While[
  Length@l < 100,
  While[k = f;
   Not[And @@ ((# + k)[[2]] < EuclideanDistance[#[[1]], k[[1]]] & /@ l)]];
   AppendTo[l, k]];
Graphics[{Circle @@@ l, FaceForm[Transparent], EdgeForm[Red], 
         Polygon[{{0, 0}, {0, 10}, {10, 10}, {10, 0}, {0, 0}}]}]

Mathematica graphics

$\endgroup$
  • $\begingroup$ Hmm… is Rectangle[] not affected by FaceForm[]? $\endgroup$ – J. M. will be back soon Jun 2 '15 at 14:05
  • $\begingroup$ @J. M. I believe it is. Why? $\endgroup$ – Dr. belisarius Jun 2 '15 at 14:07
  • $\begingroup$ Ah, I thought it was the reason why you used Polygon[] instead… $\endgroup$ – J. M. will be back soon Jun 2 '15 at 14:10
  • $\begingroup$ @J. M. Nah, I want a cute expression for the vertex ordering, and still working on that. $\endgroup$ – Dr. belisarius Jun 2 '15 at 14:12
  • $\begingroup$ can the circles be colored (off course random colored) I mean their circumstances be colored!?? $\endgroup$ – Unbelievable Jun 2 '15 at 16:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.