Search code examples
image3dwolfram-mathematicaplotmathematica-8

Place an image on the XY plane in a 3D Plot in Mathematica


Please consider the following, from the followings from

Can we generate "foveated Image" in Mathematica

Clear[acuity];

acuity[distance_, x_, y_, blindspotradius_] :=

 With[{\[Theta] = ArcTan[distance, Sqrt[x^2 + y^2]]},
      Clip[(Chop@Exp[-Abs[\[Theta]]/(15. Degree)] - .05)/.95, 
                     {0,1}] (1.-Boole[(x + 100.)^2 + y^2 <= blindspotradius^2])]

Plot3D[acuity[250., x, y, 9], {x, -256, 256}, {y, -256, 256}, 
PlotRange -> All, Axes -> False, PlotPoints -> 40, 
ExclusionsStyle -> Automatic, Boxed -> False, Mesh -> None]

enter image description here

How could I add the photo below on the X & Y plane. Then have the surface plotted transparent. Is it possible ? (image obtained with a solution in the question mentioned above).

enter image description here


Solution

  • i = Import["https://i.sstatic.net/0EizO.png"];
    p = {{0, 0}, {1, 0}, {1, 1}, {0, 1}};
    Show@{
      Plot3D[
       acuity[250., x, y, 9], {x, -256, 256}, {y, -256, 256},
       PlotRange -> All, PlotPoints -> 40,ExclusionsStyle -> Automatic,Axes -> False,
       Boxed -> False,   Mesh -> None,    PlotStyle -> Directive[Opacity[0.5]]],
      Graphics3D[{Texture[i],
        Polygon[Join[#, {0}] & /@ (2 p - 1) 256,   VertexTextureCoordinates -> p]}
      ]}
    

    enter image description here

    Edit

    Dealing with AspectRatio[], as requested in your comments:

    p = {{0, 0}, {1, 0}, {1, 1}, {0, 1}};
    r = First@#/Last@# &@Dimensions@ImageData@i;
    a = 1.4;
    Show@{Plot3D[
             acuity[250., a x, a y, 9], {x, -256  , 256 }, {y, -256 r , 256 r }, 
              PlotRange -> All, PlotPoints -> 40, ExclusionsStyle -> Automatic, 
              Axes -> False, Boxed -> False, Mesh -> None, 
              PlotStyle -> Directive[Opacity[0.5]], AspectRatio -> r], 
      Graphics3D[{Texture[i], 
                 Polygon[{{-256 , -256 r, 0}, { 256 , -256 r , 0}, 
                          { 256 ,  256 r, 0}, {-256 ,  256 r, 0}}, 
                 VertexTextureCoordinates -> p]}]}
    

    enter image description here