本文介绍了向多面体的面添加文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以自动将任何文本添加到多面体的面上,就像这个手动绘制的图形所示(示例的奇数编号方案不相关):

Is it possible to automate the addition of any text to the faces of a polyhedron, like this manually-drawn graphic shows (the example's odd numbering scheme isn't relevant):

标记顶点很容易:

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

(即使某些文本被放置在隐藏顶点的形状前面.这可能是可解决的.)

(even though some of the text is placed in front of the shape for vertices that are hidden. That's probably soluble.)

但是当我尝试对人脸做同样的事情时,没有任何效果.PolyhedronData["Dodecahedron", "Faces"] 返回一个 GraphicsComplex,而不是坐标.

But when I tried to do the same thing for faces, nothing worked. PolyhedronData["Dodecahedron", "Faces"] returns a GraphicsComplex, rather than coordinates.

我是否忽略了一个简单的解决方案/选项?

Am I overlooking an easy solution/option?

感谢这些答案,他们都很出色.如果我能将 szabolcs 答案的文本放置与 belisarius 的文本质量结合起来,完美的解决方案就在眼前!

thanks for these answers, they're all brilliant. If I could combine the text placing of szabolcs' answer with the text quality of belisarius', the perfect solution is in sight!

推荐答案

这是一个时髦的方法:

(* 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 = N@face;
  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, First@Ordering[up.# &  /@ pts, -1]];
  r2 = Transpose[{{#2, -#1} & @@ topmost, topmost}];
  r2 /= Norm[r2];
  Rescale[pts2.r2]
]

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

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

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

演示一个SmallRhombicosidodecahedron":

这篇关于向多面体的面添加文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 23:47