6

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.

Thanks,

Update

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.

Mahdi
  • 1,619
  • 10
  • 23
  • 7
    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 04:11
  • 2
    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 06:41
  • 4
    @kirma: Only if you also constrain angles to force the polygons to be regular. Otherwise I think there is quite a bit of freedom. –  Feb 25 '14 at 06: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
  • @kirma: That's right. It's not completely random but since the length of edge represents a chemical bond, it should be the same for all cells. – Mahdi Feb 25 '14 at 14:26
  • 1
    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 Answers1

7

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, 
  convexHull]

Mathematica graphics

and further

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

Mathematica graphics

halirutan
  • 112,764
  • 7
  • 263
  • 474
  • 1
    Might generate the random points like this: http://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