4

In a 3D graphic, if I wrap a figure, for example,

imagewrapped = 
 With[{Lx = 10, Ly = 10, Nx = 5, Ny = 5, r0 = 2, ftsz = 12}, 
  Graphics3D[{Table[{Sphere[{ix Lx, iy Ly, 0}, r0]}, {ix, 1, Nx}, {iy,
       1, Ny}], Red, 
    Table[Text[Style[ix, ftsz, Bold], {ix Lx, 0, 0}], {ix, 1, Nx}], 
    Cyan, Table[
     Text[Style[iy, ftsz, Bold], {0, iy Ly, 0}], {iy, 1, Ny}]}, 
   Boxed -> False, Lighting -> Automatic, ViewPoint -> {1, 1, 1}, 
   ImageSize -> {Automatic, 100}, Method -> {"ShrinkWrap" -> True}]]

image wrapped

some text disappear. How can I wrap the figure without loosing information?

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
Tony Dong
  • 869
  • 9
  • 16
  • Why did you decide to shrinkwrap the figure? It seems to look ok when shrinkwrap is False. – DavidC Mar 15 '13 at 16:21
  • @ David, actually, I have other primitives in my final figure. It will have huge white margins, that's why I need to wrap it. – Tony Dong Mar 15 '13 at 16:34

3 Answers3

6

Among the answers linked by Mr. Wizard, there's also my label3D function. Looking at that, I think in your case it would work as a replacement for Text as well. In that answer, I set a HoldFirst attribute, but I think it's not that convenient here. So I would suggest executing the definition for label3D in the linked answer, followed by

ClearAttributes[label3D, HoldFirst]

imagewrapped = 
 With[{Lx = 10, Ly = 10, Nx = 5, Ny = 5, r0 = 2, ftsz = 12}, 
  Graphics3D[{Table[{Sphere[{ix Lx, iy Ly, 0}, r0]}, {ix, 1, Nx}, {iy,
       1, Ny}], Glow[Red], 
    Table[label3D[
      Style[ix, ftsz, Red, Bold], {ix Lx, 0, 0}, {-5, 0, 0}, 0], {ix, 
      1, Nx}], Glow[Cyan], Table[
     label3D[Style[iy, ftsz, Cyan, Bold], {0, iy Ly, 0}, {0, 5, 0}, 
      0], {iy, 1, Ny}]}, Boxed -> False, Lighting -> Automatic, 
   ViewPoint -> {1, 1, 1}, ImageSize -> {Automatic, 100}, 
   Method -> {"ShrinkWrap" -> True}]]

3d labels

This seems to be treated correctly by ShrinkWrap. To make the labels look as much like the Text labels, I gave them a Glow to prevent them to display with shading.

Jens
  • 97,245
  • 7
  • 213
  • 499
3

The text seems to be laid on after the ShrinkWrapped size is determined. One simple suggestion is to include an almost transparent (Opacity[1/255]) sphere at the position of each letter to prevent clipping. This is less than ideal for several reasons, among them:

  • The spheres change size along with the graphic while the text remains an absolute size.
  • The spheres as subject to perspective scaling while the text is not.
  • Even when carefully sized the edges of the spheres do not perfectly align with the text so the wrapping will be inexact.

A better approach might be to create actual 3D text as Mark did here. That should be respected by the ShrinkWrap algorithm along with the other 3D primitives.

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
3

As a variant of Mr.Wizard's suggestion, you might place an essentially clear cuboid around the figure with text. The following is inserted into Graphics3D[{...}]

{Opacity[0.01], EdgeForm[], Cuboid[{-2, -2, -2}, {50, 50, 2}]}

EdgeForm[] prevents the edges from being displayed.

Mathematica graphics

DavidC
  • 16,724
  • 1
  • 42
  • 94