2
$\begingroup$

I have the following code to draw a lattice path in 3D:

path11 = {121, 122, 123, 118, 93, 88, 63, 38, 39, 34, 29, 4, 5};
mpg[path1_] := Module[{pth, e1, v1},
  pth = PathGraph[path1, DirectedEdges -> True];
  e1 = DirectedEdge[#[[1]], #[[2]]] & /@ EdgeList[pth];
  v1 = VertexList[pth];
  PathGraph[v1, e1, 
   VertexCoordinates -> (GraphEmbedding[g3d][[#]] & /@ v1), 
   EdgeStyle -> {Thickness[0.5], Red}, VertexStyle -> {Thick, Red}]
  ]
g3d = With[{n = 5}, 
   Graph3D[GridGraph[{n, n, n}, DirectedEdges -> True], 
    EdgeStyle -> Thick, VertexCoordinates -> Tuples[Range[n], 3]]];
mpg[path11]

enter image description here

All I really need is to make the red edges thicker, so that, when overlayed as below:

ClearAll[tr]
path11 = {121, 122, 123, 118, 93, 88, 63, 38, 39, 34, 29, 4, 5};
tr[g_, pp_] := 
 MapAt[GeometricTransformation[#, 
    TranslationTransform[
     First[Transpose@
        CoordinateBounds[Cases[pp, Cuboid[x_] :> x, All]]] - 
      First[Transpose@CoordinateBounds@GraphEmbedding[g]]]] &, 
  Show@g, {1}]
col1 = Yellow;
col2 = Blue;
col3 = White;
col4 = Red;
col5 = Black;
thickness = 0.1;
opacity = 0;
g3d = With[{n = 5}, 
   Graph3D[GridGraph[{n, n, n}, DirectedEdges -> True], 
    EdgeStyle -> Thick, VertexCoordinates -> Tuples[Range[n], 3]]];
h1 = Graphics3D[{Gray, Opacity[0.5], 
    Table[Line[{{i, j, 1}, {i, j, 5}}], {i, 1, 5}, {j, 1, 5}], 
    Table[Line[{{i, 1, k}, {i, 5, k}}], {i, 1, 5}, {k, 1, 5}], 
    Table[Line[{{1, j, k}, {5, j, k}}], {j, 1, 5}, {k, 1, 5}]}];
h2 = Graphics3D[{col5, Opacity[opacity], Thickness[thickness], 
    Table[Line[{{i, j, 1}, {i, j, 5}}], {i, 1, 5}, {j, -4, 0}], 
    Table[Line[{{i, -4, k}, {i, 0, k}}], {i, 1, 5}, {k, 1, 5}], 
    Table[Line[{{1, j, k}, {5, j, k}}], {j, -4, 0}, {k, 1, 5}]}];
mpg[path1_] := Module[{pth, e1, v1},
  pth = PathGraph[path1, DirectedEdges -> True];
  e1 = DirectedEdge[#[[1]], #[[2]]] & /@ EdgeList[pth];
  v1 = VertexList[pth];
  PathGraph[v1, e1, 
   VertexCoordinates -> (GraphEmbedding[g3d][[#]] & /@ v1), 
   EdgeStyle -> {Thickness[0.5], col4}, VertexStyle -> {Thick, col4}]
  ]
tness = 0.007;
PlanePartitionDiagram[l_List] := 
 Module[{i, j, k}, 
  Graphics3D[{EdgeForm[{Black, Thickness[tness]}], 
    Table[Cuboid[{i, j, 1}, {i + 1, j + 1, 1}], {i, 1, 
      4}, {j, -4, -1}], 
    Table[Cuboid[{1, j, k}, {1, j + 1, k + 1}], {j, -4, -1}, {k, 1, 
      4}], Table[
     Cuboid[{i, -4, k}, {i + 1, -4, k + 1}], {i, 1, 4}, {k, 1, 4}], 
    EdgeForm[{Black, Thickness[tness]}], 
    Table[Cuboid[{j, -i, k}], {i, Length[l]}, {j, Length[l[[i]]]}, {k,
       l[[i, j]]}]}, Boxed -> False, ViewAngle -> Automatic, 
   ViewCenter -> {0.5`, 0.5`, 0.5`}, ViewMatrix -> Automatic, 
   ViewPoint -> {1.084062790590325`, 1.0986455196656841`, 
     0.7859935675156864`}, ViewProjection -> "Orthographic", 
   ViewRange -> All, ViewVector -> Automatic, 
   ViewVertical -> {0.14035775337566414`, 0.18444203971701364`, 
     0.9727696721487384`}, 
   Lighting -> {{"Directional", 
      col1, {{0, 0, 1}, {0, 0, 0}}}, {"Directional", 
      col2, {{0, 1, 0}, {0, 0, 0}}}, {"Directional", 
      col3, {{1, 0, 0}, {0, 0, 0}}}}]]
pp1 = PlanePartitionDiagram[{{2, 2, 2, 2}, {2, 2, 2, 0}, {3, 0, 0, 
     0}, {3, 0, 0, 0}}];
fplot11 = 
 Show[pp1, tr[mpg[path11], pp1], 
  Epilog -> 
   Inset[Style["(a)", 43, FontFamily -> "Latin Modern Math"], 
    Offset[{-350, -2}, Scaled[{1, 1}]], {Left, Top}]]

It gives this, but with more visible edges:

enter image description here

I had thought to just increase the Thickness via EdgeStyle in PathGraph, but this does not respond i.e. the edge thickness appears independent of this number.

This is done in the mpg function in the code above, and is currently set to 0.5.

What can I do to make the red lattice path below clearly stay on top of the graphic?

Edit:

With Style[fplot11, RenderingOptions -> {"3DRenderingMethod" -> "BSPTree"}], I get

enter image description here

$\endgroup$
7
  • 1
    $\begingroup$ If you do: Style[fplot11, RenderingOptions -> {"3DRenderingMethod" -> "BSPTree"}] then the path should stand out but the plot will be slow to update. This works because BSP trees are better for resolving draw order for very close objects. Other aspects of the plot will look broken at some angles though. $\endgroup$
    – flinty
    Commented May 3, 2021 at 15:03
  • $\begingroup$ I'm getting small "nicks" taken out of each black edge, halfway along. $\endgroup$
    – apg
    Commented May 3, 2021 at 15:25
  • 1
    $\begingroup$ No. Minimal problem is one that focusses on the core of the problem. Is it essential to your problem that some cub faces be colored yellow and others blue? Of course not. So why waste our time with code that involves that?? Do we need to see the $a)$ in the figure? Of course not. Does the solid need that complex shape? No. Does lighting and its direction have anything to do with the problem? Again, no. GeometricTransformation? Nada. You'll get more help (and possibly solve your problem yourself) if you eliminate all the confusing, time-wasting irrelevant information. $\endgroup$ Commented May 3, 2021 at 17:00
  • 2
    $\begingroup$ Each of those things can impact whether the path is visible, given their order in the code, I often find this with Mathematica. Even the lighting itself may be part of the problem. I will post just the lattice path itself and see if the edge's can be made thicker, but again, the rendering solution provided above would not have been given if I hadn't done that. So there are two sides to the story of posting the exact code in this case, I think. $\endgroup$
    – apg
    Commented May 3, 2021 at 17:17
  • 1
    $\begingroup$ Also, each of the geometric transformation steps have the potential to change some hugely mysterious part of the rendering procedure. Its difficult to rule out the impact of any individual command in why this thing is not rendering properly. Definitely a good idea to give the simplest example of the problem faced, however, as you say. $\endgroup$
    – apg
    Commented May 3, 2021 at 17:29

1 Answer 1

3
$\begingroup$

If you set the EdgeShapeFunction specifically to Arrow, rather than Automatic, then specify the Thickness individually, they start looking thicker.

This can be done by replacing the mpg function above with:

mpg[path1_] := Module[{pth, e1, v1},
  pth = PathGraph[path1, DirectedEdges -> True];
  e1 = DirectedEdge[#[[1]], #[[2]]] & /@ EdgeList[pth];
  v1 = VertexList[pth];
  PathGraph[v1, e1, 
   VertexCoordinates -> (GraphEmbedding[g3d][[#]] & /@ v1), 
   EdgeShapeFunction -> "Arrow", 
   EdgeStyle -> (# -> {Thickness[0.009], Red} & /@ e1), 
   VertexStyle -> {Thick, Red}]
  ]

enter image description here

$\endgroup$

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.