# Making a Voronoi diagram bounded by the convex hull

Consider the following:

SeedRandom["blah"];
pts = RandomReal[1, {50, 2}];

{cm = ConvexHullMesh[pts],
vm = VoronoiMesh[pts, Epilog -> {Red, PointSize[Small], Point[pts]}]} // GraphicsRow


I want to generate the Voronoi diagram bounded by the convex hull. I had tried using RegionIntersection but all I get is the original convex hull. Is there a way to cut out the parts of the Voronoi diagram that are outside the convex hull, such that the result is still a MeshRegion object?

Here is an approach that should get you there:

SeedRandom["blah"]; pts = RandomReal[1, {50, 2}];
cm = ConvexHullMesh[pts];
vm = VoronoiMesh[pts, Epilog -> {Red, PointSize[Small], Point[pts]}];


The idea is to find the RegionIntersection of the Voronoi cells with the convex hull of the sites, and to combine these regions to get the Voronoi diagram bounded by the convex hull:

prim = MeshPrimitives[vm, 2];
allreg = RegionIntersection[cm, BoundaryDiscretizeRegion @ #] & /@ prim;
allprim = Map[MeshPrimitives[#, 2] &, allreg][[All, 1]];


We now have the Voronoi cells bounded by the convex hull. Let's visualize it:

gr = Graphics[{{EdgeForm[Black], RandomColor[], #} & /@ allprim, Point[pts]}]


Together with the original Voronoi diagram:

Show[vm, gr]


To obtain a MeshRegion from the bounded Voronoi diagram we simply do the following:

reg = DiscretizeGraphics @ RegionPlot @ allreg


We can check that it is indeed a MeshRegion:

{MeshRegionQ[reg], Head[reg]}


{True, MeshRegion}

Update

Here is a simplified approach thanks to @J.M.:

SeedRandom["blah"]; pts = RandomReal[1, {50, 2}];
cm = ConvexHullMesh[pts];
vm = VoronoiMesh[pts];
ch = MeshPrimitives[cm, 2][[1]];
DiscretizeGraphics[RegionIntersection[ch, #] & /@ MeshPrimitives[vm, 2]]

• As it turns out, generating the bounded Voronoi diagram can be done quite compactly: ch = MeshPrimitives[cm, 2][[1]]; DiscretizeGraphics[RegionIntersection[ch, #] & /@ MeshPrimitives[vm, 2]] Commented Dec 21, 2016 at 13:03
• @J.M. That's a better approach. Do you want to add that as an answer? Commented Dec 21, 2016 at 19:19
• I'm okay with you editing your answer to show the simplification. :) Commented Dec 22, 2016 at 1:30
• @J.M. Done. :) ${}$ Commented Dec 22, 2016 at 2:15