TransWikia.com

Embed a rose flower image in 3D space with axes labeled in UTF8

Mathematica Asked by chikitin on January 29, 2021

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.

One Answer

  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

Answered by flinty on January 29, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP