5
$\begingroup$

I am trying to create an image in which a rose flower image in a 3D space with axes labeled in UTF8! Labels don't render correctly and not sure how to put the image at say the original of XYZ space.

Show[Graphics3D@{
    Text[Style[ToString["بوسه", CharacterEncoding ->"UTF8"], Bold, Large, Red, FontFamily -> "Times"], {0, 2, 0}],
    Text[Style[ToString["خنده", CharacterEncoding ->"UTF8"], Bold, Large, Blue, FontFamily -> "Times"], {-2, 0, 0}],
    Text[Style[ToString["پرواز",CharacterEncoding ->"UTF8"], Bold, Large, Purple, FontFamily -> "Times"], {0, 0, 2}]},
PlotRange -> {{-2, 2}, {0, 2}, {-2, 2}}, AspectRatio -> 1, 
Boxed -> True, Axes -> True, AxesOrigin -> {0, 0, 0}]

Also is it possible to have it animated? by rotation or utilizing other images?

Any help would be appreciated.

$\endgroup$
5
$\begingroup$
  1. You need to use CharacterEncoding->"Unicode" to get the Arabic to show up in the text.
  2. Use BoxRatios->1 instead of AspectRatio->1 to avoid 2D distortion.
  3. Use Texture[rose] combined with the VertexTextureCoordinates of a Polygon to get the rose image onto a quad in the 3D graphics. I assume you already have an image like my "rose.png"
rose = Import["rose.png"];
Show[Graphics3D@{Text[
    Style[ToString["بوسه", CharacterEncoding -> "Unicode"], Bold, 
     Large, Red, FontFamily -> "Times"], {0, 2, 0}], 
   Text[Style[ToString["خنده", CharacterEncoding -> "Unicode"], Bold, 
     Large, Blue, FontFamily -> "Times"], {-2, 0, 0}], 
   Text[Style[ToString["پرواز", CharacterEncoding -> "Unicode"], Bold,
      Large, Purple, FontFamily -> "Times"], {0, 0, 2}],
   EdgeForm[None], Texture[rose], 
    Polygon[{{-1, 0, 0}, {1, 0, 0}, {1, 1, 0}, {-1, 1, 0}}, 
    VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {0, 1}}]
   }, PlotRange -> {{-2, 2}, {0, 2}, {-2, 2}}, BoxRatios -> 1, 
 Boxed -> True, Axes -> True, AxesOrigin -> {0, 0, 0}]

rose plot

Animating a rotation is fairly simple too:

rose = Import["rose.png"];
frames = Table[
   Graphics3D[{Text[
      Style[ToString["بوسه", CharacterEncoding -> "Unicode"], Bold, 
       Large, Red, FontFamily -> "Times"], {0, 2, 0}], 
     Text[Style[ToString["خنده", CharacterEncoding -> "Unicode"], 
       Bold, Large, Blue, FontFamily -> "Times"], {-2, 0, 0}], 
     Text[Style[ToString["پرواز", CharacterEncoding -> "Unicode"], 
       Bold, Large, Purple, FontFamily -> "Times"], {0, 0, 2}],
     EdgeForm[None], Texture[rose],
     Red, 
     Rotate[Polygon[{{-1, 0, 0}, {1, 0, 0}, {1, 1, 0}, {-1, 1, 0}}, 
       VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {0, 1}}],
           θ, {0, 1, 0}]
     }, PlotRange -> {{-2, 2}, {0, 2}, {-2, 2}}, BoxRatios -> 1, 
    Boxed -> True, Axes -> True, AxesOrigin -> {0, 0, 0}, 
    ViewPoint -> {1, -2, 2}]
   , {θ, 0, 2 Pi, 0.05}];
Export["anim.gif", frames, "AnimationRepetitions" -> Infinity]

spinning rose animation


I've notified Wolfram of the Arabic left-to-right bug. For the moment, here's a workaround which rasterizes the labels in 2D first:

textlabel[str_, colour_] := 
 ColorReplace[
  Rasterize[
   Text[Style[ToString[str, CharacterEncoding -> "Unicode"], Bold, 
     Large, colour, FontFamily -> "Times"]]], White -> Transparent
  ]

rose = Import["rose.png"];
labels = MapThread[textlabel, {{"پرواز","بوسه","خنده"}, {Blue, Red, Purple}}];
frames = Table[
   Graphics3D[{EdgeForm[None], Texture[rose], Red, 
     Rotate[Polygon[{{-1, 0, 0}, {1, 0, 0}, {1, 1, 0}, {-1, 1, 0}}, 
       VertexTextureCoordinates -> {{0,0},{1,0},{1,1},{0,1}}], θ, {0,1,0}]},
    AxesLabel -> labels, PlotRange -> {{-2,2},{0,2},{-2,2}}, 
    BoxRatios -> 1, Boxed -> True, Axes -> True, 
    AxesOrigin -> {0, 0, 0}, ViewPoint -> {1, -2, 2}],
   {θ, 0, 2 Pi, 0.05}];
Export["anim.gif", frames, "AnimationRepetitions" -> Infinity]

arabic labels bug workaround

| improve this answer | |
$\endgroup$
  • 2
    $\begingroup$ I just noticed a bug in Mathematica. If you do Graphics[{Text[Style[ToString["بوس", CharacterEncoding -> "Unicode"], FontSize -> 70]]}] then Arabic is written right-to-left which is correct. But if change Graphics to Graphics3D, it is incorrectly rendered left-to-right. $\endgroup$ – flinty Aug 31 at 18:05
  • $\begingroup$ Unfortunately. This bug makes the output useless for my presentation. $\endgroup$ – chikitin Sep 3 at 15:53
  • 1
    $\begingroup$ @chikitin I've reported it to Wolfram. $\endgroup$ – flinty Sep 3 at 16:11
  • 1
    $\begingroup$ @chikitin I've added a workaround to display Arabic AxesLabels properly by rasterizing the label first. $\endgroup$ – flinty Sep 3 at 16:32
  • $\begingroup$ Thank you very much. You are great! $\endgroup$ – chikitin Sep 4 at 1:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.