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.

  • 7
    $\begingroup$ 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... $\endgroup$
    – ciao
    Commented Feb 25, 2014 at 4:11
  • 2
    $\begingroup$ 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. $\endgroup$
    – kirma
    Commented Feb 25, 2014 at 6:41
  • 4
    $\begingroup$ @kirma: Only if you also constrain angles to force the polygons to be regular. Otherwise I think there is quite a bit of freedom. $\endgroup$
    – user484
    Commented Feb 25, 2014 at 6:57
  • $\begingroup$ @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. $\endgroup$
    – Mahdi
    Commented Feb 25, 2014 at 14:24
  • 1
    $\begingroup$ Run this then ListDensityPlot[ ArrayFlatten[{{pts, RandomReal[1, {Length[pts], 1}]}}], InterpolationOrder -> 0, Mesh -> All]. Is this what you're looking for? $\endgroup$
    – Szabolcs
    Commented Feb 25, 2014 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

  • 1
    $\begingroup$ Might generate the random points like this: mathematica.stackexchange.com/q/2594/12 $\endgroup$
    – Szabolcs
    Commented Feb 25, 2014 at 12:11
  • $\begingroup$ 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. $\endgroup$
    – Mahdi
    Commented Feb 25, 2014 at 14:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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