3
$\begingroup$

Here are some examples of what I am talking about using Voronoi for simplicity:

Given:

Blank voronoi mesh. It is white with a black skeleton.

That can be colored depending on which cell is randomly chosen: A voronoi with one black cell. Then bordering cells are dark gray. The ones that border the outside are lighter gray. It is side by side with the Same voronoi but a different cell chosen to be black. Then bordering cells are dark gray. The ones that border the outside are lighter gray.

I feel like there would be a better name for this concept, but I don't know it.

This code can highlight a random Voronoi cell:

Graphics[ {GraphicsComplex[ MeshCoordinates[vor], {Thick, Blue, MeshCells[vor, 1], MeshCells[vor, 0], Opacity[0.2], White, MeshCells[vor, 2]} ], Black, RandomChoice[MeshPrimitives[vor, 2]] } ] 

and you can highlight the adjacent cells to it using (did for a different voronoi):

vor=VoronoiMesh[data]; fromLabel[vm_, labels_] := Ordering[Length /@ vm["Faces"]][[labels]] toLabel[vm_, indices_] := ReplaceAll[ indices, Thread[Ordering[Length /@ vm["Faces"]]->Range[Length[vm["Faces"]]]] ] highlightAdjacentFaces[vm_, label_] := HighlightMesh[ vm, Thread[{2, toLabel[vm, vm["FaceFaceConnectivity"][[fromLabel[vm, label]]]]}] ] vm = vor; highlightAdjacentFaces[vm, Length[data]] 

Which gives:

Adjacent cells highlighted.

While a natural thought is to look at the adjacency matrix of the cells, then test each component to see if it shares a vertex or edge with the region before it, this seems like a very procedural approach and it is not very Mathematica-like.

I am not just interested in convex or Voronoi tilings. For example, this lemon tiling is also interesting:

Identical lemon shaped tilings formed by translated sine functions. The colors are different though.

which I highlighted the rasterized version using this code and Paint:

rowLineQuantity=RandomInteger[{2,10}]; oddColQuantity=RandomInteger[{1,10}]; Plot[ Table[ Sin[x+FractionBox["1", "2"] (-1-SuperscriptBox[RowBox[{"(", RowBox[{"-", "1"}], ")"}], "i"])*Pi]-2 i,{i,1,rowLineQuantity}],{x,-Pi/2,FractionBox["1", "2"] (-1+4 *oddColQuantity) \[Pi]}, AspectRatio->Automatic,Axes->False,PlotStyle->Blue] 
$\endgroup$
1
  • 2
    $\begingroup$ MeshConnectivityGraph and GraphDistance might come in handy. $\endgroup$ Commented Jul 16, 2024 at 15:31

1 Answer 1

5
$\begingroup$

As suggested by @flinty, use MeshConnectivityGraph and GraphDistance.

colorByDistance[mesh_, start_, cf_ : ColorData["CoffeeTones"]] := Module[{polygons, graph, distances}, polygons = MeshPrimitives[mesh, 2]; graph = MeshConnectivityGraph[mesh, 2]; distances = GraphDistance[graph, VertexList[graph][[start]]]; Graphics[{EdgeForm[Black], MapThread[{cf[#2/Max[distances]], #1} &, {polygons, distances}]}] ] SeedRandom[100]; mesh = VoronoiMesh[RandomReal[{-1, 1}, {100, 2}]]; colorByDistance[mesh, 70] 

enter image description here

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.