1
$\begingroup$

This question already has an answer here:

I want to draw pictrue like this:

enter image description here

My code is:

mycountry=BoundaryDiscretizeGraphics@CountryData["China","Polygon"];



    list={Disk[RandomPoint[mycountry],RandomReal[0.01]]};
        While[Length[list]<50,disk=Disk[center=
RandomPoint[mycountry],r=RandomReal[{1,5}]];If[And@@((EuclideanDistance[center,
#[[1]]]>r+#[[2]])&/@list),
    AppendTo[list,disk]]]//AbsoluteTiming

(*{19.357, Null}*)



    Graphics[Transpose[{RandomColor[Hue[1/3,
NormalDistribution[.6,.2],NormalDistribution[.6,.07]],list//Length],Disk@@@list}]]

enter image description here

As you see,The way ahead of me is long,the Length[list] is just 50,but the time is 19s.Then I use the @belisarius 's SameTest in here,Then the While can be:

        list={Disk[RandomPoint[mycountry],RandomReal[0.01]]};
        BlockRandom@While[Length[list]<50,disk=Disk[RandomPoint[mycountry],
RandomReal[{1,5}]];list=Union[Append[list,disk],SameTest->(EuclideanDistance[#1[[1]],#2[[1]]]<(#1[[2]]+#2[[2]])&)]]//AbsoluteTiming

(*{44.0782, Null}*)

Although I have tried SameTest->(EuclideanDistance[#1[[1]],#2[[1]]]<(#1[[2]]+#2[[2]])&),SameTest -> (! RegionAlmostDisjointQ[{#1, #2}] &)andSameTest->(!RegionRegionDisjoint[#1,#2]&),The speed is slow still.By the way,I found a bug in a undocument function of Region`RegionSubset,such as

    If[Region`RegionSubset[disk,mycountry]&&And@@((EuclideanDistance[center,
#[[1]]]>r+#[[2]])&/@list),AppendTo[list,disk]]

The Region`RegionSubset don't work.So anybody can try a faster version to me?

ps:(and how can I input "`" normally in stackexchange?)

$\endgroup$

marked as duplicate by rm -rf Sep 28 '15 at 4:10

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    $\begingroup$ If you want the disks packed densely, consult: mathematica.stackexchange.com/questions/87676/… $\endgroup$ – David G. Stork Sep 28 '15 at 2:06
  • $\begingroup$ @DavidG.Stork Thanks for your prompt.And the post's typesets is disorder,Can you tell me how to type a context symbol?I should be refind the typesets. $\endgroup$ – yode Sep 28 '15 at 2:20
  • $\begingroup$ @yode I showed you how to do it, and then you changed it back. But you can still see how to do it in the question's history. $\endgroup$ – C. E. Sep 28 '15 at 2:25
  • $\begingroup$ Is there a difference between this question and this question? $\endgroup$ – C. E. Sep 28 '15 at 2:28
  • $\begingroup$ @Pickett I'm sorry to hear that.Or you can change it again.¯ㅂ¯,The networ acess to SE is too slow in my country. $\endgroup$ – yode Sep 28 '15 at 2:30