Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Someone know how can I get the correct crop of this Voronoi image using RegionFunction? Voronoi Diagram

As you can see, there is a lot of undesired white regions inside the left polygon. Some clue on how to correct it? Here is the code using PointInPoly and RegionFunction:

PointInPoly[{x_, y_}, poly_List] := 
 Module[{i, j, c = False, npol = Length[poly]}, 
  For[i = 1; j = npol, i <= npol, j = i++, 
   If[((((poly[[i, 2]] <= y) && (y < 
             poly[[j, 2]])) || ((poly[[j, 2]] <= y) && (y < 
             poly[[i, 2]]))) && (x < (poly[[j, 1]] - 
             poly[[i, 1]])*(y - poly[[i, 2]])/(poly[[j, 2]] - 
              poly[[i, 2]]) + poly[[i, 1]])), c = ¬ c];];


poli={0.5,0.5}+#&/@Table[0.3{Cos[2π k/6],Sin[2π k/6]},{k,0,6}];

    ,RegionFunction->Function[{x,y,z},PointInPoly[{x, y}, poli]]


GraphicsRow@{g1, g2}

Important point, I can't use image manipulate functions.

What I really need is the list of polygons inside the cropped area. I get it using g1[[1]]

share|improve this question
up vote 9 down vote accepted

V10 way

m = VoronoiMesh @ RandomReal[{-1, 1}, {25, 2}];
p = Table[{Cos[i], Sin[i]}, {i, Pi/3., 2 Pi, Pi/3}] // Polygon // DiscretizeGraphics;

enter image description here

  RegionIntersection[DiscretizeGraphics@#, p] & /@  MeshPrimitives[m, 2],
 ] // RegionPlot[#, AspectRatio -> Automatic] &

enter image description here

Old stuff

Using PolygonIntersection introduced here:


g2 = ListDensityPlot[pts, Sequence @@ opt];

po = Cases[
           Normal @ g2,
           Polygon[x_, y__] :> x,

po2 = PolygonIntersection[Polygon/@{poli, #}, AllTriangles->False] & /@ po /. 
                                                          Polygon[{{}}] -> Sequence[];

     Graphics[{Hue /@ Range[0, 1, 1/(Length[po2] - 1)], po2} // Transpose],
     g2}, ImageSize -> 700]

enter image description here

Coordinates of vertices you are looking for are in po2, you can just remove Polygon heads from inside.

This is undocumented function but the method will work for each function calculating graphics intersection. I just used it because it is short.

share|improve this answer
Tks @Cuba. Exactly what I need. I'll wait just for respect the protocol. :) – Murta Aug 27 '13 at 14:02
@Murta I'm glad it works as you want it to work. Of course, no need to hurry. :) – Kuba Aug 27 '13 at 15:42

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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