Draw circles and compute -
Clash Royale CLAN TAG#URR8PPP
up vote
7
down vote
favorite
The following code draws the polygons of 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:
The black points are pts
, the red ones the vertices of the Voronoi mesh.
My questions:
- How can I draw circles around each point in
pts
with a given radius $r$, such as $0.18$? - How can I compute
<sum of circle areas>-<area of overlaps of the circles>
, i.e.
$$left(sum_cinmathrmCirclesmathrmArea(c)right)-left(sum_oinmathrmOverlapsmathrmArea(o)right)$$
computational-geometry
add a comment |Â
up vote
7
down vote
favorite
The following code draws the polygons of 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:
The black points are pts
, the red ones the vertices of the Voronoi mesh.
My questions:
- How can I draw circles around each point in
pts
with a given radius $r$, such as $0.18$? - How can I compute
<sum of circle areas>-<area of overlaps of the circles>
, i.e.
$$left(sum_cinmathrmCirclesmathrmArea(c)right)-left(sum_oinmathrmOverlapsmathrmArea(o)right)$$
computational-geometry
add a comment |Â
up vote
7
down vote
favorite
up vote
7
down vote
favorite
The following code draws the polygons of 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:
The black points are pts
, the red ones the vertices of the Voronoi mesh.
My questions:
- How can I draw circles around each point in
pts
with a given radius $r$, such as $0.18$? - How can I compute
<sum of circle areas>-<area of overlaps of the circles>
, i.e.
$$left(sum_cinmathrmCirclesmathrmArea(c)right)-left(sum_oinmathrmOverlapsmathrmArea(o)right)$$
computational-geometry
The following code draws the polygons of 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:
The black points are pts
, the red ones the vertices of the Voronoi mesh.
My questions:
- How can I draw circles around each point in
pts
with a given radius $r$, such as $0.18$? - How can I compute
<sum of circle areas>-<area of overlaps of the circles>
, i.e.
$$left(sum_cinmathrmCirclesmathrmArea(c)right)-left(sum_oinmathrmOverlapsmathrmArea(o)right)$$
computational-geometry
edited Sep 8 at 22:33


Lukas Lang
5,2181525
5,2181525
asked Sep 8 at 13:11


Eman
926
926
add a comment |Â
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
6
down vote
accepted
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.
Implicit regions
r = 0.18;
regs = ImplicitRegion[
Sqrt[(x - #[[1]])^2 + (y - #[[2]])^2] <= r, x, y] & /@ pts;
Circles drawing
Show[mesh,
Graphics[Cyan, Circle[#, r] & /@ pts, Black, Point[pts], Red,
Point[vertices]], Axes -> True]
Union
c = Ceiling[Max[pts] + r, 0.5];
AbsoluteTiming[
dregs = DiscretizeRegion[RegionUnion[regs], -2, 2, -2, 2,
ImageSize -> Medium]
]
RegionMeasure[dregs]
(* 1.99653 *)
Union Intersection
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]
]
RegionMeasure[dregs] - RegionMeasure[dires]
(* 1.56288 *)
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.
– Eman
Sep 8 at 13:39
1
@Eman See my edit. It should be close to what you want.
– Anton Antonov
Sep 8 at 13:50
Thanks so much for your help and your edit. I really appreciate that. Your edit is what I was looking for. Thanks so much.
– Eman
Sep 8 at 14:20
add a comment |Â
up vote
5
down vote
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]]
Thanks for your help.
– Eman
Sep 8 at 14:18
1
@eman, my pleasure.
– kglr
Sep 8 at 14:24
add a comment |Â
up vote
3
down vote
I think it is much better to use RegionMeasure
on the undiscretized regions. For instance:
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
:
RegionMeasure @ BooleanRegion[
BooleanCountingFunction[1, 25],
disks
]
1.58624
although this version is slower than Antons.
Thanks so much for your help.
– Eman
Sep 9 at 14:02
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
6
down vote
accepted
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.
Implicit regions
r = 0.18;
regs = ImplicitRegion[
Sqrt[(x - #[[1]])^2 + (y - #[[2]])^2] <= r, x, y] & /@ pts;
Circles drawing
Show[mesh,
Graphics[Cyan, Circle[#, r] & /@ pts, Black, Point[pts], Red,
Point[vertices]], Axes -> True]
Union
c = Ceiling[Max[pts] + r, 0.5];
AbsoluteTiming[
dregs = DiscretizeRegion[RegionUnion[regs], -2, 2, -2, 2,
ImageSize -> Medium]
]
RegionMeasure[dregs]
(* 1.99653 *)
Union Intersection
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]
]
RegionMeasure[dregs] - RegionMeasure[dires]
(* 1.56288 *)
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.
– Eman
Sep 8 at 13:39
1
@Eman See my edit. It should be close to what you want.
– Anton Antonov
Sep 8 at 13:50
Thanks so much for your help and your edit. I really appreciate that. Your edit is what I was looking for. Thanks so much.
– Eman
Sep 8 at 14:20
add a comment |Â
up vote
6
down vote
accepted
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.
Implicit regions
r = 0.18;
regs = ImplicitRegion[
Sqrt[(x - #[[1]])^2 + (y - #[[2]])^2] <= r, x, y] & /@ pts;
Circles drawing
Show[mesh,
Graphics[Cyan, Circle[#, r] & /@ pts, Black, Point[pts], Red,
Point[vertices]], Axes -> True]
Union
c = Ceiling[Max[pts] + r, 0.5];
AbsoluteTiming[
dregs = DiscretizeRegion[RegionUnion[regs], -2, 2, -2, 2,
ImageSize -> Medium]
]
RegionMeasure[dregs]
(* 1.99653 *)
Union Intersection
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]
]
RegionMeasure[dregs] - RegionMeasure[dires]
(* 1.56288 *)
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.
– Eman
Sep 8 at 13:39
1
@Eman See my edit. It should be close to what you want.
– Anton Antonov
Sep 8 at 13:50
Thanks so much for your help and your edit. I really appreciate that. Your edit is what I was looking for. Thanks so much.
– Eman
Sep 8 at 14:20
add a comment |Â
up vote
6
down vote
accepted
up vote
6
down vote
accepted
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.
Implicit regions
r = 0.18;
regs = ImplicitRegion[
Sqrt[(x - #[[1]])^2 + (y - #[[2]])^2] <= r, x, y] & /@ pts;
Circles drawing
Show[mesh,
Graphics[Cyan, Circle[#, r] & /@ pts, Black, Point[pts], Red,
Point[vertices]], Axes -> True]
Union
c = Ceiling[Max[pts] + r, 0.5];
AbsoluteTiming[
dregs = DiscretizeRegion[RegionUnion[regs], -2, 2, -2, 2,
ImageSize -> Medium]
]
RegionMeasure[dregs]
(* 1.99653 *)
Union Intersection
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]
]
RegionMeasure[dregs] - RegionMeasure[dires]
(* 1.56288 *)
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.
Implicit regions
r = 0.18;
regs = ImplicitRegion[
Sqrt[(x - #[[1]])^2 + (y - #[[2]])^2] <= r, x, y] & /@ pts;
Circles drawing
Show[mesh,
Graphics[Cyan, Circle[#, r] & /@ pts, Black, Point[pts], Red,
Point[vertices]], Axes -> True]
Union
c = Ceiling[Max[pts] + r, 0.5];
AbsoluteTiming[
dregs = DiscretizeRegion[RegionUnion[regs], -2, 2, -2, 2,
ImageSize -> Medium]
]
RegionMeasure[dregs]
(* 1.99653 *)
Union Intersection
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]
]
RegionMeasure[dregs] - RegionMeasure[dires]
(* 1.56288 *)
edited Sep 8 at 14:12
answered Sep 8 at 13:32
Anton Antonov
21.6k164107
21.6k164107
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.
– Eman
Sep 8 at 13:39
1
@Eman See my edit. It should be close to what you want.
– Anton Antonov
Sep 8 at 13:50
Thanks so much for your help and your edit. I really appreciate that. Your edit is what I was looking for. Thanks so much.
– Eman
Sep 8 at 14:20
add a comment |Â
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.
– Eman
Sep 8 at 13:39
1
@Eman See my edit. It should be close to what you want.
– Anton Antonov
Sep 8 at 13:50
Thanks so much for your help and your edit. I really appreciate that. Your edit is what I was looking for. Thanks so much.
– Eman
Sep 8 at 14:20
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.
– Eman
Sep 8 at 13:39
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.
– Eman
Sep 8 at 13:39
1
1
@Eman See my edit. It should be close to what you want.
– Anton Antonov
Sep 8 at 13:50
@Eman See my edit. It should be close to what you want.
– Anton Antonov
Sep 8 at 13:50
Thanks so much for your help and your edit. I really appreciate that. Your edit is what I was looking for. Thanks so much.
– Eman
Sep 8 at 14:20
Thanks so much for your help and your edit. I really appreciate that. Your edit is what I was looking for. Thanks so much.
– Eman
Sep 8 at 14:20
add a comment |Â
up vote
5
down vote
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]]
Thanks for your help.
– Eman
Sep 8 at 14:18
1
@eman, my pleasure.
– kglr
Sep 8 at 14:24
add a comment |Â
up vote
5
down vote
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]]
Thanks for your help.
– Eman
Sep 8 at 14:18
1
@eman, my pleasure.
– kglr
Sep 8 at 14:24
add a comment |Â
up vote
5
down vote
up vote
5
down vote
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]]
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]]
edited Sep 9 at 5:40
answered Sep 8 at 13:33
kglr
159k8184384
159k8184384
Thanks for your help.
– Eman
Sep 8 at 14:18
1
@eman, my pleasure.
– kglr
Sep 8 at 14:24
add a comment |Â
Thanks for your help.
– Eman
Sep 8 at 14:18
1
@eman, my pleasure.
– kglr
Sep 8 at 14:24
Thanks for your help.
– Eman
Sep 8 at 14:18
Thanks for your help.
– Eman
Sep 8 at 14:18
1
1
@eman, my pleasure.
– kglr
Sep 8 at 14:24
@eman, my pleasure.
– kglr
Sep 8 at 14:24
add a comment |Â
up vote
3
down vote
I think it is much better to use RegionMeasure
on the undiscretized regions. For instance:
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
:
RegionMeasure @ BooleanRegion[
BooleanCountingFunction[1, 25],
disks
]
1.58624
although this version is slower than Antons.
Thanks so much for your help.
– Eman
Sep 9 at 14:02
add a comment |Â
up vote
3
down vote
I think it is much better to use RegionMeasure
on the undiscretized regions. For instance:
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
:
RegionMeasure @ BooleanRegion[
BooleanCountingFunction[1, 25],
disks
]
1.58624
although this version is slower than Antons.
Thanks so much for your help.
– Eman
Sep 9 at 14:02
add a comment |Â
up vote
3
down vote
up vote
3
down vote
I think it is much better to use RegionMeasure
on the undiscretized regions. For instance:
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
:
RegionMeasure @ BooleanRegion[
BooleanCountingFunction[1, 25],
disks
]
1.58624
although this version is slower than Antons.
I think it is much better to use RegionMeasure
on the undiscretized regions. For instance:
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
:
RegionMeasure @ BooleanRegion[
BooleanCountingFunction[1, 25],
disks
]
1.58624
although this version is slower than Antons.
answered Sep 9 at 6:57


Carl Woll
56.3k272147
56.3k272147
Thanks so much for your help.
– Eman
Sep 9 at 14:02
add a comment |Â
Thanks so much for your help.
– Eman
Sep 9 at 14:02
Thanks so much for your help.
– Eman
Sep 9 at 14:02
Thanks so much for your help.
– Eman
Sep 9 at 14:02
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f181488%2fdraw-circles-and-compute-sum-of-circle-areas-area-of-overlaps-of-the-circles%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password