3
$\begingroup$

I want to create a MeshRegion that is VoronoiMesh bounded by the associated ConvexHullMesh. I followed the procedure in the answer for this post, but the resulting MeshRegion is very wrong.

This is what my VoronoiMesh and ConvexHullMesh look like: enter image description here

My desire is to have a MeshRegion of only the area of the VoronoiMesh outlined in red. I followed the code example given in the post I linked above:

cm = ConvexHullMesh[pts];
ch = MeshPrimitives[cm, 2][[1]];
vm = VoronoiMesh[pts];
DiscretizeGraphics[RegionIntersection[ch, #] & /@ MeshPrimitives[vm, 2]]

But this code produces the following result, usually...

enter image description here

I say "usually", because if I execute the same code repeatedly, every so often it will return this:

enter image description here

Which is exactly what I want! But if I run the same code again, it starts returning the messed up mesh all over again.

Is this a bug in the DiscretizeGraphics function? Is there some way to force it to preserve the Voronoi Cells?

Edit: Per request, the pts array.

pts={{0, 1.2438972614940857},{0, 0.9636875567529508},{0, 0.8225803919688134},{0, 0.7331683530782342},{0, 0.6697636516843404},{0, 0.621660423493867},{0, 0.5834791607160031},{0, 0.5521750801894381},{0, 0.5258755396778766},{0, 0.503355706442203},{0, 0.48377548219861094},{0, 0.466536436368803},{0, 0.45119892374060755},{0, 0.43743155261595146},{0, 0.424979049640617},{0.40341098865872727, 1.2438972614940857},{0.19715420497821629, 0.9636875567529508},{0.12006445981523653, 0.8225803919688134},{0.08212050964280186, 0.7331683530782342},{0.060356953228638974, 0.6697636516843404},{0.046587915896771304, 0.621660423493867},{0.0372599696436135, 0.5834791607160031},{0.030613294892946417, 0.5521750801894381},{0.025689538419132386, 0.5258755396778766},{0.021927896295954766, 0.503355706442203},{0.018981141802975915, 0.48377548219861094},{0.016624266804637206, 0.466536436368803},{0.014705881752657036, 0.45119892374060755},{0.013120867272804126, 0.43743155261595146},{0.011794246773185007, 0.424979049640617},{0.1141139564736296, 1.055368189826202},{0.0530330848801975, 0.4177262245371366},{0.030242010479031564, 0.22651105945647884},{0.01940636797710833, 0.1433290355141969},{0.013449151385547397, 0.09943176705071363},{0.009839341521273401, 0.07332661224428688},{0.007493690057701841, 0.05648423519099168},{0.0058870837983598205, 0.04495479970632894},{0.0047404626160789665, 0.03669862257794525},{0.0038946423004167724, 0.030573142103318948},{0.00325355735008812, 0.025896568309477543},{0.0027565088483396017, 0.02224094520339375},{0.0023636512876428115, 0.019326274418946333},{0.002047970466101388, 0.016962908952657334},{0.0017906382342701035, 0.015018572254201145},{0.03489248974145652, 0.2903012797360848},{0.019324838289647896, 0.1265437771907919},{0.012302490995349531, 0.06988972730031659},{0.008535217100858894, 0.04401390363286231},{0.0062778121647453404, 0.030135071213654857},{0.0048169455945446405, 0.021863594776775144},{0.0038163905986524577, 0.01655198031239352},{0.00310059081533189, 0.012945694082926644},{0.0025705130959543286, 0.010389159515215744},{0.002166801374764703, 0.008513212629188511},{0.0018520994615352727, 0.007097327135107546},{0.0016019316391343431, 0.00600330527064082},{0.0013997111167807707, 0.005141038929909376},{0.0012338698645754046, 0.004449780505717137},{0.0010961379852522184, 0.003887391498126782},{0.015820808928586148, 0.10328654672879056},{0.01000921582518309, 0.05415604526990609},{0.00699827746735632, 0.03340973888528694},{0.005216702054007623, 0.022709634389713303},{0.004065876243066826, 0.01646437213356673},{0.0032746169962278807, 0.012498327209336324},{0.00270456003800711, 0.009820341814810604},{0.0022786801291417524, 0.00792571457066499},{0.0019511364644942534, 0.006535184160489869},{0.0016931646995521621, 0.005483925761159057},{0.0014859225238663455, 0.004669497716848316},{0.0013166189845158608, 0.00402547699355619},{0.001176305978520755, 0.003507245368741902},{0.0010585607312054211, 0.003083919717300501},{0.0009586694586583974, 0.002733566498891702},{0.007468259413584087, 0.045102310193744596},{0.005467111240200174, 0.027563795078613097},{0.0042654305944460754, 0.01895107354629903},{0.003470784068930911, 0.014004722315624765},{0.0029097308304887512, 0.01086706803143234},{0.002494344903452149, 0.008734689974476137},{0.002175526371727223, 0.007210159206752012},{0.0019238061697594067, 0.0060770072520880125},{0.0017204790239930007, 0.005208444099178768},{0.001553128223754225, 0.004525858863449971},{0.0014132037113772247, 0.003978227422733865},{0.0012946351436568693, 0.0035311586794299185},{0.0011929995796185397, 0.003160728216274545},{0.0011050019153798433, 0.0028498394397423825},{0.0010281394354921568, 0.0025859889021257933},{0.007468259413584087, 0},{0.0054671112402001724, 0},{0.0042654305944460754, 0},{0.003470784068930911, 0},{0.0029097308304887512, 0},{0.002494344903452149, 0},{0.002175526371727223, 0},{0.0019238061697594067, 0},{0.0017204790239930007, 0},{0.001553128223754225, 0},{0.0014132037113772247, 0},{0.0012946351436568693, 0},{0.0011929995796185397, 0},{0.0011050019153798433, 0},{0.0010281394354921568, 0},{1, 2},{0, 0}};
$\endgroup$
  • 1
    $\begingroup$ Could you provide the data for pts? I can't reproduce this issue using my own points. $\endgroup$ – Chip Hurst Jan 16 '19 at 2:12
  • $\begingroup$ Edited the original post and added the pts array at the end. $\endgroup$ – GibBits Jan 16 '19 at 3:21
  • $\begingroup$ You added a boundary-conditions tag - how do boundary conditions come into play here? Could you elaborate on that a bit please. $\endgroup$ – user21 Jan 16 '19 at 7:04
  • $\begingroup$ I'm using the Voronoi Mesh to perform Natural Neighbor Interpolation, and it doesn't work outside the Convex Hull nor in unbounded cells. The Convex Hull is defined by the boundary conditions of the system I am interpolating. $\endgroup$ – GibBits Jan 16 '19 at 15:49
2
$\begingroup$

I'm not really sure what's going on, but I can provide a workaround.

First, I notice if I just discretize the first 99 cells, I get the desired result 1 out of 3 times. Strange.

ints = RegionIntersection[ch, #] & /@ MeshPrimitives[vm, 2];

Table[{DiscretizeGraphics[ints], DiscretizeGraphics[ints[[1 ;; 99]]]}, 100] // Tally

enter image description here

To workaround this we can construct the MeshRegion manually by joining the vertices and constructing the cell indices.

coords = ints[[All, 1]];

runs = Partition[Accumulate[Prepend[Length /@ coords, 0]], 2, 1];

MeshRegion[Join @@ coords, Polygon[Range[#1 + 1, #2] & @@@ runs]]

enter image description here

$\endgroup$
  • $\begingroup$ This works really well and, most importantly, consistently! Thank you so much! $\endgroup$ – GibBits Jan 16 '19 at 15:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.