# How can Mathematica be used to create a 3D Maze with text like this? Interesting Graphic that creates a cool visual 3D maze which could possibly be done in Mathematica but I haven't seen an example in 3D. Assuming a Randomized Prim's algorithm will work for the maze creation regardless; how can text be added to this process to provide the results similar to the image below?

• This is not a real 3D object. It is full of impossible Penrose triangles. – Szabolcs May 16 '17 at 13:50
• @Szabolcs ah yes I see that now! Thanks for pointing that out. Certainly not possible as a match, but maybe just as a maze? – R Hall May 16 '17 at 14:31
• @george2079 I've made a simple grid but need to trim it based on the letters and perspective. cAxes = {{{0, 0, 0}, {0, 0, 1}}, {{0, 0, 0}, {0, 1, 0}}, {{0, 0, 0}, {1, 0, 0}}}; a = Graphics3D[{Line /@ cAxes}, Boxed -> False]; b = Graphics3D[{GrayLevel[0.25], Table[Line /@ {{{x, y, 0}, {x, y, 1}}, {{x, 0, y}, {x, 1, y}}, {{0, x, y}, {1, x, y}}}, {x, 0, 1, 0.1}, {y, 0, 1, 0.1}]}]; Show[a, b] – R Hall May 16 '17 at 18:39
• @RHall: It's best to edit that code into your original question, rather than posting it as an additional content. When you do so, indent each line by four spaces and our website will automatically format it as code rather than text. – Michael Seifert May 19 '17 at 13:02

To produce a maze, we can simply find a spanning tree of a grid graph.

IGraph/M has a function to generate random spanning trees of graphs, IGRandomSpanningTree.

Here's a demo:

IGRandomSpanningTree[
IGMakeLattice[{5, 5, 5}],
VertexCoordinates -> Tuples[Range, {3}],
VertexShape -> None,
EdgeStyle -> CapForm["Round"],
EdgeShapeFunction -> (Tube[Line[#1], 0.2] &)
] You could use GridGraph instead of IGMakeLattice. I used the latter today because I was having crashes with the first.

With the new lattice generation features in IGraph/M, we can also start with a different grid than a rectangular one. How about a Cairo tiling?

g = IGMeshGraph@IGLatticeMesh["CairoPentagonal"];

IGRandomSpanningTree[g, VertexCoordinates -> GraphEmbedding[g],
GraphStyle -> "Web", VertexSize -> Medium] Or a mostly hexagonal maze on the surface of a sphere.

mesh = DiscretizeRegion[Sphere[], PrecisionGoal -> 2, MaxCellMeasure -> 2];
VertexCoordinates -> PropertyValue[{mesh, 2}, MeshCellCentroid]];

IGRandomSpanningTree[g, VertexCoordinates -> GraphEmbedding[g],
VertexShape -> None,
EdgeStyle -> Directive[Orange, CapForm["Round"]],
EdgeShapeFunction -> (Tube[Line[#1], 0.04] &)
] • Just nitpicking: I'd congratulate you if you would have found a truly hexagonal tiling on a sphere! (Also, I see pentagons there.) Although discretization doesn't really guarantee it, this looks like a maze over edges of a Goldberg polyhedron... – kirma Apr 29 '18 at 6:42
• Nice work thank you! – R Hall Apr 30 '18 at 12:38
• @kirma Of course, you are right. I posted in a rush. I corrected the phrasing now. – Szabolcs Apr 30 '18 at 13:19