Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I am using Voronoi Poligonization as a support form simulating island erosion; my data are the output of VoronoiDiagram, DelaunayTriangulation, the starting point and the list of point that now are sea. I am not working whit BoundedDiagram so I made sure all unlimited poligons are in sea.

Now I need to show this output like in DiagramPlot, but with sea cells colored blue, and land cells colored in brown.
Can you give me some code example or indications on where to search?

More in general, I need to have a planar graph of which I know vertex coordinates and the edges, what function should I use to choose the color for the faces of the graph?

share|improve this question
2  
Please post a sample of what you already have. –  Mr.Wizard Sep 22 '13 at 0:17
    
To shorten the sample you can use RandomReal to generate a set of points. –  ssch Sep 22 '13 at 0:18
    
1  
Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the FAQs! 3) When you see good Q&A, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. ALSO, remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign –  Vitaliy Kaurov Sep 22 '13 at 20:16

2 Answers 2

up vote 11 down vote accepted

This is just a flow of consciousness... I think you are talking about something like this:

<< ComputationalGeometry`

data = {{4.4, 14}, {6.7, 15.25}, {6.9, 12.8}, {2.1, 11.1}, {9.5, 14.9}, 
       {13.2, 11.9}, {10.3, 12.3}, {6.8, 9.5}, {3.3, 7.7}, {0.6, 5.1}, 
       {5.3, 2.4}, {8.45, 4.7}, {11.5, 9.6}, {13.8, 7.3}, {12.9, 3.1}, {11, 1.1}};

ubd = DiagramPlot[data, LabelPoints -> False]

enter image description here

So here I think what you want to do:

Graphics[{FaceForm[Brown], EdgeForm[White], 
  Polygon[Select[vorvert[[#]] & /@ vorval[[All, 2]], 
    Cases[#, _Ray] == {} &]]}, Background -> Blue]

enter image description here

On the other hand image processing does it too:

MatrixPlot[MorphologicalComponents[ubd // Binarize] /. {1 -> Blue, 0 -> White, 
   x_Integer /; (x =!= 1) -> Brown}, Frame -> False]

enter image description here

but the payoff is that you lost information about Graphics primitives and went to rasterized images, - which may be fine if you care about visual only.

If you'd figure out how to sea-land with BoundedDiagram-type diagrams, then it maybe easier, because there is another way to make Voronoi. For example here coloring only approximately circular core of Voronoi cells:

plt = ListDensityPlot[RandomReal[1, {500, 3}], 
   InterpolationOrder -> 0];
plg = Cases[plt, Polygon[{x__}] :> x, ∞];
cplg = Select[plg, 
   EuclideanDistance[Mean[plt[[1, 1]][[#]]], 
      Mean[plt[[1, 1]]]] < .3 &];
Graphics[{
   GraphicsComplex[
   plt[[1, 1]], {FaceForm[Blue], EdgeForm[Black], Polygon[plg]}],
  GraphicsComplex[
   plt[[1, 1]], {FaceForm[Red], EdgeForm[White], Polygon[cplg]}]
  }]

enter image description here

share|improve this answer
3  
I believe you could define plg = Cases[plt, Polygon[{x__}] :> x, ∞] (+1) –  Mr.Wizard Sep 23 '13 at 13:08
    
@Mr.Wizard Yes, much better, updated, thanks ;) –  Vitaliy Kaurov Sep 23 '13 at 18:03
    
:-) -- by the way, what is the benefit of keeping the GraphicsComplex form here? Since the points must be resolved for EuclideanDistance anyway it seems to me it would be simpler to use coordinates directly. –  Mr.Wizard Sep 24 '13 at 1:12
    
You might consider using Nearest as belisarius did here. –  Mr.Wizard Sep 24 '13 at 7:23
    
@Mr.Wizard I am catching a plane today, but I will have to revisit this after - thanks! –  Vitaliy Kaurov Sep 24 '13 at 15:02

Well, another solution using V10 functionality:

data = {{4.4, 14}, {6.7, 15.25}, {6.9, 12.8}, {2.1, 11.1}, {9.5, 
    14.9}, {13.2, 11.9}, {10.3, 12.3}, {6.8, 9.5}, {3.3, 7.7}, {0.6, 
    5.1}, {5.3, 2.4}, {8.45, 4.7}, {11.5, 9.6}, {13.8, 7.3}, {12.9, 
    3.1}, {11, 1.1}};

The Voronoi diagram:

vor = VoronoiMesh[data]

Mathematica graphics

We get the Polygons that make up the Voronoi diagram and select the unbounded ones which will represent the sea, while the bounded ones will represent the land. The unbounded polygons must have at least one point in their RegionBounds identical to the overall RegionBounds of the Voronoi diagram.

cells = Map[MeshCoordinates[vor][[#]] &, MeshCells[vor, 2], {2}];

EDIT A much easier way to do the above is:

cells = MeshPrimitives[vor, 2]; (* I knew there was a better way *)

The region bounds of the Voronoi diagram is obtained simply as

RegionBounds[vor]

{{-2.7, 17.1}, {-2.4375, 18.7875}}

Using the new IntersectingQ we can see which polygons are unbounded/bounded:

bound = IntersectingQ[Flatten@RegionBounds[vor], Flatten@RegionBounds[#]] & /@ cells;

Now we can plot the regions:

polys = Transpose[{bound, cells}] /. {True -> Blue, False -> Brown};

Graphics[{EdgeForm[{White}], polys, Yellow, Point[data]}]

Mathematica graphics

share|improve this answer

Your Answer

 
discard

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.