Подтвердить что ты не робот

Добавить текст в грань многогранника

Можно ли автоматизировать добавление любого текста к граням многогранника, как это показано на рисунке вручную (пример нечетной схемы нумерации не имеет значения):

labelled faces of dodecahedron

Легко было обозначить вершины:

c = 1;
Show[{Graphics3D[
   Text[c++, #] & /@ PolyhedronData["Dodecahedron", "VertexCoordinates"]], 
   PolyhedronData["Dodecahedron"]},
   Boxed -> False]

labelled edges of dodecahedron

(хотя часть текста помещена перед формой для скрытых вершин. Вероятно, это разрешимо.)

Но когда я пытался сделать то же самое для лиц, ничего не сработало. PolyhedronData["Dodecahedron", "Faces"] возвращает GraphicsComplex, а не координаты.

Я пропустил простое решение/вариант?

Изменить: спасибо за эти ответы, все они блестящие. Если бы я мог совместить текстовое размещение ответа szabolcs с качеством текста belisarius ', идеальное решение в поле зрения!

4b9b3361

Ответ 1

Здесь фанковый подход:

(* this function just transforms the polygon onto the [0,1] 2D square *)
vtc[face_, up_:{0,0,1}] := Module[{pts, pts2, centre, r, r2, topmost},
  pts = [email protected];
  centre = Mean[pts];
  pts = (# - centre & /@ pts);
  r = SingularValueDecomposition[pts][[3]];

  (* these two lines ensure that the text on the outer face 
     of a convex polyhedron is not mirrored *)
  If[Det[r] < 0, r = -r];
  If[Last[centre.r] < 0, r = r.RotationMatrix[\[Pi], {1, 0, 0}]];

  pts2 = Most /@ (pts.r);
  topmost = Part[pts2, [email protected][up.# &  /@ pts, -1]];
  r2 = Transpose[{{#2, -#1} & @@ topmost, topmost}];
  r2 /= Norm[r2];
  Rescale[pts2.r2]
]

faces = First /@ [email protected]@PolyhedronData["Dodecahedron", "Faces"];

numbers = 
  Graphics[Text[
      Style[#, Underlined, FontFamily -> "Georgia", 
       FontSize -> Scaled[.3]]]] & /@ [email protected][faces];

Graphics3D[
 MapThread[{Texture[#1], 
    Polygon[#2, VertexTextureCoordinates -> vtc[#2]]} &, {numbers, 
   faces}],
 Boxed -> False
 ]

enter image description here

Демонстрация "SmallRhombicosidodecahedron":

enter image description here

Ответ 2

a = PolyhedronData["Dodecahedron", "Faces"] /.    GraphicsComplex -> List;
c = 1;
Show[{Graphics3D[
   Text[c++, #] & /@ (Mean /@ (a[[1, #]] & /@ a[[2, 1]]))], 
    PolyhedronData["Dodecahedron"]}, Boxed -> False]

Изменить

Возможно, лучше:

Show[{Graphics3D[
         MapIndexed[Text[#2, #1] &, 
             Mean /@ (PolyhedronData["Dodecahedron", "VertexCoordinates"][[#]] & /@ 
                      PolyhedronData["Dodecahedron", "FaceIndices"])]], 
         PolyhedronData["Dodecahedron"]}, Boxed -> False]

Edit

Или

text = Style[#, 128] & /@ Range[12]
[email protected]
 Riffle[Texture /@ text, 
       (Append[#1, {VertexTextureCoordinates -> 
          With[{n = Length[First[#1]]}, Table[1/2 {Cos[2 Pi i/n], Sin[2 Pi i/n]}+ 
                                           {1/2, 1/2}, {i, 0, n - 1}]]}] &) /@ 
   Flatten[Normal[PolyhedronData["Dodecahedron", "Faces"]]]]

enter image description here