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 want to generate a network of random cells like the following picture:

enter image description here

The general idea is to generate some random points (x,y) as coordinate of a vertex and then randomly choose some of these points to connect them to achieve (almost) a random cellular network since there are two constraints:

  1. The length of edges is constant.
  2. Degree of each vertex is 3.



I have been thinking about this problem for a while. Here's the conclusion:

By starting from a perfect honeycomb, we perform a series of random "neighbor switching" process:

enter image description here

By performing successive neighbor switching, we are able to build cells with different size.

share|improve this question
What have you tried? Post at least some code showing attempts: In general, this site is not intended as a "will work for free and rep. points" kind of place... –  ciao Feb 25 '14 at 4:11
If you really want all edge lengths to be the same, I think you end up seeing only the three regular tilings of a plane; not very random. –  kirma Feb 25 '14 at 6:41
@kirma: Only if you also constrain angles to force the polygons to be regular. Otherwise I think there is quite a bit of freedom. –  Rahul Feb 25 '14 at 6:57
@rasher: I have tried to generate some vortices (x,y) by "RandomReal" function. Then I tried to choose randomly a vertex and connect that to three other vortex since degree of each vertex should be 3. I should choose those three points from neighbors which I can do that by defining a upper limit on the distance. The main problem is to keep the length of edge the same and the degree 3. –  Mahdi Feb 25 '14 at 14:24
Run this then ListDensityPlot[ ArrayFlatten[{{pts, RandomReal[1, {Length[pts], 1}]}}], InterpolationOrder -> 0, Mesh -> All]. Is this what you're looking for? –  Szabolcs Feb 25 '14 at 15:05

1 Answer 1

Fixing the edge length makes the problem harder. Otherwise, maybe this here gives an idea

<< ComputationalGeometry`
data = .9 Flatten[
    Table[{x, y} + .07 RandomReal[{-1, 1}, {2}], {x, -1, 
      1, .2}, {y, -1, 1, .2}], 1];
delval = DelaunayTriangulation[data];
convexHull = ConvexHull[data];
gr = DiagramPlot[data, ##, LabelPoints -> False] & @@ 
 BoundedDiagram[{{-1, -1}, {1, -1}, {1, 1}, {-1, 1}}, data, delval, 

Mathematica graphics

and further

gr /. {Point[___] :> Sequence[], 
  Line[pts_] :> ({EdgeForm[{Thick, Black}], 
     ColorData["Rainbow", RandomReal[]], Polygon[pts]})}

Mathematica graphics

share|improve this answer
Might generate the random points like this: mathematica.stackexchange.com/q/2594/12 –  Szabolcs Feb 25 '14 at 12:11
Thank you so much. I got the idea. Maybe 'DelaunayTriangulation' is not the choice here and I have to have a specific code for this part. –  Mahdi Feb 25 '14 at 14:32

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.