3
$\begingroup$

I cannot figure out how to label the vertices of a GraphicsComplex, for example

Graphics3D[
     GraphicsComplex[{{1, -1, 1}, {0, 0, 0}, {1, 1, 1}, {0, 0, 2}, {-1, 0,1}},
        {Polygon[{2, 4, 5}], Polygon[{1, 3, 4}], Polygon[{1, 2, 3}]}]]

I've seen that this can be done for Graph and GraphPlot using VertexLabelling, but as far as I know, there isn't a similar option for GraphicsComplex.

$\endgroup$
1
  • 4
    $\begingroup$ You've seen Text[]? GraphicsComplex[pts, Text[#, #] & /@ pts] $\endgroup$ Aug 22, 2015 at 0:35

2 Answers 2

4
$\begingroup$

Expanding on comment from Guess who it is, I think he pretty much had it nailed but instead of mapping onto pts I believe you need to use Range[Length[pts]].

GraphicsComplex will use the point number to indicate the position of the graphic object.

With[
 {
  pts = {{1, -1, 1}, {0, 0, 0}, {1, 1, 1}, {0, 0, 2}, {-1, 0, 1}}
  },
 Graphics3D[{
   Opacity[0.5],
   GraphicsComplex[pts,
    {
     Red, Polygon[{2, 4, 5}],
     Blue, Polygon[{1, 3, 4}],
     Green, Polygon[{1, 2, 3}],
     }
    ],
   Opacity[1],
   Black,
   GraphicsComplex[pts,
    Text[Style[ToString[#], Background -> White, 16], #] & 
      /@ Range[Length[pts]]
    ]
   }]
 ]

This makes a plot that looks like

Mathematica graphics

$\endgroup$
0
$\begingroup$

You can also post-process the Graphics3D output to add the labels:

g0 = Graphics3D[GraphicsComplex[{{1, -1, 1}, {0, 0, 0}, {1, 1, 1}, {0, 0, 2}, {-1, 0, 1}},
  {Polygon[{2, 4, 5}], Polygon[{1, 3, 4}], Polygon[{1, 2, 3}]}]];

Insert[g0, Text[Style[#, 24, Background -> Yellow], #] & /@ 
  Range[Length @ g0[[1, 1]]], {1, 2, 1}]

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.