Draw circles and compute -

Draw circles and compute <sum of circle areas>-<area of overlaps of the circles>



The following code draws the polygons of VoronoiMesh[pts]:


VoronoiMesh[pts]


SeedRandom[3];
pts = RandomReal[-1, 1, 25, 2];
mesh = VoronoiMesh[pts];
vertices = MeshCoordinates[mesh];
Show[mesh, Graphics[Black, Point[pts], Red, Point[vertices]]]



The output is:



enter image description here



The black points are pts, the red ones the vertices of the Voronoi mesh.


pts


pts


<sum of circle areas>-<area of overlaps of the circles>




3 Answers
3



I am not sure are you interested in the union of the disks or the union sans the intersections. The code below can be used for both cases.


r = 0.18;
regs = ImplicitRegion[
Sqrt[(x - #[[1]])^2 + (y - #[[2]])^2] <= r, x, y] & /@ pts;


Show[mesh,
Graphics[Cyan, Circle[#, r] & /@ pts, Black, Point[pts], Red,
Point[vertices]], Axes -> True]



enter image description here


c = Ceiling[Max[pts] + r, 0.5];

AbsoluteTiming[
dregs = DiscretizeRegion[RegionUnion[regs], -2, 2, -2, 2,
ImageSize -> Medium]
]



enter image description here


RegionMeasure[dregs]

(* 1.99653 *)


ires = DeleteCases[
Flatten[Table[
RegionIntersection[regs[[i]], regs[[j]]], i, 1,
Length[regs], j, i + 1, Length[regs]]], _EmptyRegion];

AbsoluteTiming[
dires = DiscretizeRegion[RegionUnion[ires], -c, c, -c, c,
ImageSize -> Medium, Frame -> True, PlotRange -> -c, c, -c, c]
]



enter image description here


RegionMeasure[dregs] - RegionMeasure[dires]

(* 1.56288 *)





$begingroup$
Thanks so much for your answer. But, I want to draw circle around each pts point, which is represented by black points and keeps also the voronoi diagram. Then, detect the overlapping areas occurs between these circles. Then calculate the sum of these circles' areas subtracted by the overlapping areas. I think, there is a difference between the circle and the disk.
$endgroup$
– Eman
Sep 8 '18 at 13:39






$begingroup$
@Eman See my edit. It should be close to what you want.
$endgroup$
– Anton Antonov
Sep 8 '18 at 13:50





$begingroup$
Thanks so much for your help and your edit. I really appreciate that. Your edit is what I was looking for. Thanks so much.
$endgroup$
– Eman
Sep 8 '18 at 14:20





$begingroup$
Excuse me, If I want to make only 15 circles with radius of 0.18 and the other 10 circles with radius of 0.25,then compute <sum of circle areas>-<area of overlaps of the circles> , what should I modify in your code to do that??
$endgroup$
– Eman
Sep 12 '18 at 16:55



<sum of circle areas>-<area of overlaps of the circles>





$begingroup$
@Eman You can have a separate list of radiuses and use MapThread when making the implicit regions. E.g. regs = MapThread[ ImplicitRegion[ Sqrt[(x - #1[[1]])^2 + (y - #1[[2]])^2] <= #2, x, y] &, pts, rs] .
$endgroup$
– Anton Antonov
Sep 13 '18 at 12:21


MapThread


regs = MapThread[ ImplicitRegion[ Sqrt[(x - #1[[1]])^2 + (y - #1[[2]])^2] <= #2, x, y] &, pts, rs]


radius = .18;
disks = Disk[#, radius] & /@ pts;
25 Area[disks[[1]]]



2.54469


Area[RegionUnion[disks]]



2.03381


Show[mesh, Graphics[Black, Point[pts], Red, Point[vertices],
FaceForm[Opacity[.5,LightGreen]],EdgeForm[Thick,Darker@Green], disks]]



enter image description here





$begingroup$
Thanks for your help.
$endgroup$
– Eman
Sep 8 '18 at 14:18





$begingroup$
@eman, my pleasure.
$endgroup$
– kglr
Sep 8 '18 at 14:24



I think it is much better to use RegionMeasure on the undiscretized regions. For instance:


RegionMeasure


disks = Disk[#, .18]& /@ pts;

ru = RegionMeasure @ RegionUnion[disks]
RegionMeasure @ DiscretizeRegion @ RegionUnion[disks]



2.03381



1.99723



The region measure of the discretized version is almost 2% off. Similarly:


ires = DeleteCases[
Flatten @ Table[
RegionIntersection[disks[[i]], disks[[j]]],
i, 1, 25,
j, i + 1, 25
],
_EmptyRegion
];

int = RegionMeasure @ RegionUnion @ ires
RegionMeasure @ DiscretizeRegion @ RegionUnion @ ires



0.44757



0.439748



So a more accurate answer would be:


ru - int



1.58624



Finally, it is possible to get this result directly by using BooleanCountingFunction:


BooleanCountingFunction


RegionMeasure @ BooleanRegion[
BooleanCountingFunction[1, 25],
disks
]



1.58624



although this version is slower than Antons.





$begingroup$
Thanks so much for your help.
$endgroup$
– Eman
Sep 9 '18 at 14:02



Thanks for contributing an answer to Mathematica Stack Exchange!



But avoid



Use MathJax to format equations. MathJax reference.



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



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)