Randomly distributed circles inside an annulus












5












$begingroup$


With the following code:



findPoints = 
Compile[{{n, _Integer}, {low, _Real}, {high, _Real}, {minD, _Real}},
Block[{data = RandomReal[{low, high}, {1, 2}], k = 1, rv, temp},
While[k < n, rv = RandomReal[{low, high}, 2];
temp = Transpose[Transpose[data] - rv];
If[Min[Sqrt[(#.#)] & /@ temp] > minD, data = Join[data, {rv}];
k++;];];
data]];

npts = 150;
r = 0.03;
minD = 2.2 r;
low = 0;
high = 1;

SeedRandom[159]
pts = findPoints[npts, low, high, minD];
g2d = Graphics[{FaceForm@Lighter[Blue, 0.4],
EdgeForm@Directive[Thickness[0.004], Black], Disk[#, r] & /@ pts},
PlotRange -> All, Background -> Lighter@Blue];

d1 = Disk[{0.5, 0.5}, 0.5];
d2 = Disk[{0.5, 0.5}, 0.3];
annulus = RegionDifference[d1, d2];

mask2 = BoundaryDiscretizeRegion[#, {{-1, 1}, {-1, 1}},
MaxCellMeasure -> {1 -> .02}] &@BoundaryDiscretizeRegion[annulus];
r2d2 = DiscretizeGraphics[g2d, MaxCellMeasure -> {1 -> .01},
PlotRange -> All];
inside2 = RegionIntersection[r2d2, mask2]


I can produce (pseudo)randomly distributed circles inside an annulus.
enter image description here



I have two questions. The first is a ridiculous one: How can we modify the color (e.g. Red) of the DiscretizeGraphics output.



The second one is not a tricky one. I want the circles to have random radius. Any ideas of how can I achieve that?



For References about above codes see the question:



find the maximum number of not intersecting circles inside an ellipse



and references therein.










share|improve this question









$endgroup$












  • $begingroup$
    Do they all have to fit inside the annulus?
    $endgroup$
    – user5601
    2 hours ago










  • $begingroup$
    Yes, they should.
    $endgroup$
    – dimitris
    2 hours ago
















5












$begingroup$


With the following code:



findPoints = 
Compile[{{n, _Integer}, {low, _Real}, {high, _Real}, {minD, _Real}},
Block[{data = RandomReal[{low, high}, {1, 2}], k = 1, rv, temp},
While[k < n, rv = RandomReal[{low, high}, 2];
temp = Transpose[Transpose[data] - rv];
If[Min[Sqrt[(#.#)] & /@ temp] > minD, data = Join[data, {rv}];
k++;];];
data]];

npts = 150;
r = 0.03;
minD = 2.2 r;
low = 0;
high = 1;

SeedRandom[159]
pts = findPoints[npts, low, high, minD];
g2d = Graphics[{FaceForm@Lighter[Blue, 0.4],
EdgeForm@Directive[Thickness[0.004], Black], Disk[#, r] & /@ pts},
PlotRange -> All, Background -> Lighter@Blue];

d1 = Disk[{0.5, 0.5}, 0.5];
d2 = Disk[{0.5, 0.5}, 0.3];
annulus = RegionDifference[d1, d2];

mask2 = BoundaryDiscretizeRegion[#, {{-1, 1}, {-1, 1}},
MaxCellMeasure -> {1 -> .02}] &@BoundaryDiscretizeRegion[annulus];
r2d2 = DiscretizeGraphics[g2d, MaxCellMeasure -> {1 -> .01},
PlotRange -> All];
inside2 = RegionIntersection[r2d2, mask2]


I can produce (pseudo)randomly distributed circles inside an annulus.
enter image description here



I have two questions. The first is a ridiculous one: How can we modify the color (e.g. Red) of the DiscretizeGraphics output.



The second one is not a tricky one. I want the circles to have random radius. Any ideas of how can I achieve that?



For References about above codes see the question:



find the maximum number of not intersecting circles inside an ellipse



and references therein.










share|improve this question









$endgroup$












  • $begingroup$
    Do they all have to fit inside the annulus?
    $endgroup$
    – user5601
    2 hours ago










  • $begingroup$
    Yes, they should.
    $endgroup$
    – dimitris
    2 hours ago














5












5








5





$begingroup$


With the following code:



findPoints = 
Compile[{{n, _Integer}, {low, _Real}, {high, _Real}, {minD, _Real}},
Block[{data = RandomReal[{low, high}, {1, 2}], k = 1, rv, temp},
While[k < n, rv = RandomReal[{low, high}, 2];
temp = Transpose[Transpose[data] - rv];
If[Min[Sqrt[(#.#)] & /@ temp] > minD, data = Join[data, {rv}];
k++;];];
data]];

npts = 150;
r = 0.03;
minD = 2.2 r;
low = 0;
high = 1;

SeedRandom[159]
pts = findPoints[npts, low, high, minD];
g2d = Graphics[{FaceForm@Lighter[Blue, 0.4],
EdgeForm@Directive[Thickness[0.004], Black], Disk[#, r] & /@ pts},
PlotRange -> All, Background -> Lighter@Blue];

d1 = Disk[{0.5, 0.5}, 0.5];
d2 = Disk[{0.5, 0.5}, 0.3];
annulus = RegionDifference[d1, d2];

mask2 = BoundaryDiscretizeRegion[#, {{-1, 1}, {-1, 1}},
MaxCellMeasure -> {1 -> .02}] &@BoundaryDiscretizeRegion[annulus];
r2d2 = DiscretizeGraphics[g2d, MaxCellMeasure -> {1 -> .01},
PlotRange -> All];
inside2 = RegionIntersection[r2d2, mask2]


I can produce (pseudo)randomly distributed circles inside an annulus.
enter image description here



I have two questions. The first is a ridiculous one: How can we modify the color (e.g. Red) of the DiscretizeGraphics output.



The second one is not a tricky one. I want the circles to have random radius. Any ideas of how can I achieve that?



For References about above codes see the question:



find the maximum number of not intersecting circles inside an ellipse



and references therein.










share|improve this question









$endgroup$




With the following code:



findPoints = 
Compile[{{n, _Integer}, {low, _Real}, {high, _Real}, {minD, _Real}},
Block[{data = RandomReal[{low, high}, {1, 2}], k = 1, rv, temp},
While[k < n, rv = RandomReal[{low, high}, 2];
temp = Transpose[Transpose[data] - rv];
If[Min[Sqrt[(#.#)] & /@ temp] > minD, data = Join[data, {rv}];
k++;];];
data]];

npts = 150;
r = 0.03;
minD = 2.2 r;
low = 0;
high = 1;

SeedRandom[159]
pts = findPoints[npts, low, high, minD];
g2d = Graphics[{FaceForm@Lighter[Blue, 0.4],
EdgeForm@Directive[Thickness[0.004], Black], Disk[#, r] & /@ pts},
PlotRange -> All, Background -> Lighter@Blue];

d1 = Disk[{0.5, 0.5}, 0.5];
d2 = Disk[{0.5, 0.5}, 0.3];
annulus = RegionDifference[d1, d2];

mask2 = BoundaryDiscretizeRegion[#, {{-1, 1}, {-1, 1}},
MaxCellMeasure -> {1 -> .02}] &@BoundaryDiscretizeRegion[annulus];
r2d2 = DiscretizeGraphics[g2d, MaxCellMeasure -> {1 -> .01},
PlotRange -> All];
inside2 = RegionIntersection[r2d2, mask2]


I can produce (pseudo)randomly distributed circles inside an annulus.
enter image description here



I have two questions. The first is a ridiculous one: How can we modify the color (e.g. Red) of the DiscretizeGraphics output.



The second one is not a tricky one. I want the circles to have random radius. Any ideas of how can I achieve that?



For References about above codes see the question:



find the maximum number of not intersecting circles inside an ellipse



and references therein.







plotting graphics discretization






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 2 hours ago









dimitrisdimitris

2,1431331




2,1431331












  • $begingroup$
    Do they all have to fit inside the annulus?
    $endgroup$
    – user5601
    2 hours ago










  • $begingroup$
    Yes, they should.
    $endgroup$
    – dimitris
    2 hours ago


















  • $begingroup$
    Do they all have to fit inside the annulus?
    $endgroup$
    – user5601
    2 hours ago










  • $begingroup$
    Yes, they should.
    $endgroup$
    – dimitris
    2 hours ago
















$begingroup$
Do they all have to fit inside the annulus?
$endgroup$
– user5601
2 hours ago




$begingroup$
Do they all have to fit inside the annulus?
$endgroup$
– user5601
2 hours ago












$begingroup$
Yes, they should.
$endgroup$
– dimitris
2 hours ago




$begingroup$
Yes, they should.
$endgroup$
– dimitris
2 hours ago










1 Answer
1






active

oldest

votes


















4












$begingroup$

Far from efficient, but we can adapt the Neat Example from the RegionDisjoint ref page. Note that a non-uniform distribution of radii would probably speed things up.



outerReg = Annulus;

randomBall[dim_, reg_] := (
While[
!RegionWithin[reg, ball = Ball[RandomPoint[reg], RandomReal[{1/15, 1/6}]]],
(* spin *)
];
ball
)

appendDisjointBall[dim_][reg : Ball[pts_, rs_]] :=
Block[{ball = randomBall[dim, outerReg]},
While[! RegionDisjoint[ball, reg],
ball = randomBall[dim, outerReg]
];
Ball[Append[pts, #1], Append[rs, #2]] & @@ ball
]

disjointBalls[n_, dim_] :=
Nest[appendDisjointBall[dim], List /@ randomBall[dim, outerReg], n - 1]

n = 40;
scene2D = disjointBalls[n, 2];

Graphics[{
{EdgeForm[Black], GrayLevel[.9], Annulus},
{EdgeForm[Black], Thread[{RandomColor[Hue[_], n], Thread[scene2D]}]}
}]







share|improve this answer









$endgroup$













    Your Answer





    StackExchange.ifUsing("editor", function () {
    return StackExchange.using("mathjaxEditing", function () {
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
    });
    });
    }, "mathjax-editing");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "387"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f190891%2frandomly-distributed-circles-inside-an-annulus%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    4












    $begingroup$

    Far from efficient, but we can adapt the Neat Example from the RegionDisjoint ref page. Note that a non-uniform distribution of radii would probably speed things up.



    outerReg = Annulus;

    randomBall[dim_, reg_] := (
    While[
    !RegionWithin[reg, ball = Ball[RandomPoint[reg], RandomReal[{1/15, 1/6}]]],
    (* spin *)
    ];
    ball
    )

    appendDisjointBall[dim_][reg : Ball[pts_, rs_]] :=
    Block[{ball = randomBall[dim, outerReg]},
    While[! RegionDisjoint[ball, reg],
    ball = randomBall[dim, outerReg]
    ];
    Ball[Append[pts, #1], Append[rs, #2]] & @@ ball
    ]

    disjointBalls[n_, dim_] :=
    Nest[appendDisjointBall[dim], List /@ randomBall[dim, outerReg], n - 1]

    n = 40;
    scene2D = disjointBalls[n, 2];

    Graphics[{
    {EdgeForm[Black], GrayLevel[.9], Annulus},
    {EdgeForm[Black], Thread[{RandomColor[Hue[_], n], Thread[scene2D]}]}
    }]







    share|improve this answer









    $endgroup$


















      4












      $begingroup$

      Far from efficient, but we can adapt the Neat Example from the RegionDisjoint ref page. Note that a non-uniform distribution of radii would probably speed things up.



      outerReg = Annulus;

      randomBall[dim_, reg_] := (
      While[
      !RegionWithin[reg, ball = Ball[RandomPoint[reg], RandomReal[{1/15, 1/6}]]],
      (* spin *)
      ];
      ball
      )

      appendDisjointBall[dim_][reg : Ball[pts_, rs_]] :=
      Block[{ball = randomBall[dim, outerReg]},
      While[! RegionDisjoint[ball, reg],
      ball = randomBall[dim, outerReg]
      ];
      Ball[Append[pts, #1], Append[rs, #2]] & @@ ball
      ]

      disjointBalls[n_, dim_] :=
      Nest[appendDisjointBall[dim], List /@ randomBall[dim, outerReg], n - 1]

      n = 40;
      scene2D = disjointBalls[n, 2];

      Graphics[{
      {EdgeForm[Black], GrayLevel[.9], Annulus},
      {EdgeForm[Black], Thread[{RandomColor[Hue[_], n], Thread[scene2D]}]}
      }]







      share|improve this answer









      $endgroup$
















        4












        4








        4





        $begingroup$

        Far from efficient, but we can adapt the Neat Example from the RegionDisjoint ref page. Note that a non-uniform distribution of radii would probably speed things up.



        outerReg = Annulus;

        randomBall[dim_, reg_] := (
        While[
        !RegionWithin[reg, ball = Ball[RandomPoint[reg], RandomReal[{1/15, 1/6}]]],
        (* spin *)
        ];
        ball
        )

        appendDisjointBall[dim_][reg : Ball[pts_, rs_]] :=
        Block[{ball = randomBall[dim, outerReg]},
        While[! RegionDisjoint[ball, reg],
        ball = randomBall[dim, outerReg]
        ];
        Ball[Append[pts, #1], Append[rs, #2]] & @@ ball
        ]

        disjointBalls[n_, dim_] :=
        Nest[appendDisjointBall[dim], List /@ randomBall[dim, outerReg], n - 1]

        n = 40;
        scene2D = disjointBalls[n, 2];

        Graphics[{
        {EdgeForm[Black], GrayLevel[.9], Annulus},
        {EdgeForm[Black], Thread[{RandomColor[Hue[_], n], Thread[scene2D]}]}
        }]







        share|improve this answer









        $endgroup$



        Far from efficient, but we can adapt the Neat Example from the RegionDisjoint ref page. Note that a non-uniform distribution of radii would probably speed things up.



        outerReg = Annulus;

        randomBall[dim_, reg_] := (
        While[
        !RegionWithin[reg, ball = Ball[RandomPoint[reg], RandomReal[{1/15, 1/6}]]],
        (* spin *)
        ];
        ball
        )

        appendDisjointBall[dim_][reg : Ball[pts_, rs_]] :=
        Block[{ball = randomBall[dim, outerReg]},
        While[! RegionDisjoint[ball, reg],
        ball = randomBall[dim, outerReg]
        ];
        Ball[Append[pts, #1], Append[rs, #2]] & @@ ball
        ]

        disjointBalls[n_, dim_] :=
        Nest[appendDisjointBall[dim], List /@ randomBall[dim, outerReg], n - 1]

        n = 40;
        scene2D = disjointBalls[n, 2];

        Graphics[{
        {EdgeForm[Black], GrayLevel[.9], Annulus},
        {EdgeForm[Black], Thread[{RandomColor[Hue[_], n], Thread[scene2D]}]}
        }]








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 1 hour ago









        Chip HurstChip Hurst

        20.8k15789




        20.8k15789






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Mathematica Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            Use MathJax to format equations. MathJax reference.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f190891%2frandomly-distributed-circles-inside-an-annulus%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Bundesstraße 106

            Verónica Boquete

            Ida-Boy-Ed-Garten